template::icon (private)

 template::icon -name name [ -alt alt ] [ -class class ] \
    [ -iconset iconset ] [ -style style ] [ -title title ] \
    [ -invisible ]

Defined in packages/acs-templating/tcl/style-procs.tcl

Return a dict containing the HTML rendering and a potentially needed command for the ADP code. The latter are necessary for e.g. style loading. The target icon can be (1) a font glyph, (2) an image or (3) just a text. Method (1) is used for glyphicons and bootstrap icons, which is signaled by a value in the icon::map starting with a plain character. When the value starts with a slash "/", then an image will be used. When the name has no graphical counterpart (variant 3), this is signaled via an empty string. In this case, the resulting replacement will be the value of "alt" in text form. The configuration of this method is performed via the Tcl dict ::template::icon::map, which is set in tag-init.tcl

Switches:
-name (required)
-alt (optional)
used in classic images. When not specified, use 'title' attribute
-class (optional)
-iconset (optional)
force isage of this icon set
-style (optional)
-title (optional)
-invisible (optional, boolean, defaults to "f")
Returns:
dict containing 'HTML' and 'cmd'

Partial Call Graph (max 5 caller/called nodes):
%3 test_adp_parse_tags adp_parse_tags (test acs-templating) template::icon template::icon test_adp_parse_tags->template::icon template::head::add_css template::head::add_css (public) template::icon->template::head::add_css template::iconset template::iconset (private) template::icon->template::iconset Class ::xowf::test_item::Answer_manager Class ::xowf::test_item::Answer_manager (public) Class ::xowf::test_item::Answer_manager->template::icon packages/acs-templating/tcl/tag-init.tcl packages/acs-templating/ tcl/tag-init.tcl packages/acs-templating/tcl/tag-init.tcl->template::icon xowf::test_item::Answer_manager instproc postprocess_question_html xowf::test_item::Answer_manager instproc postprocess_question_html (protected) xowf::test_item::Answer_manager instproc postprocess_question_html->template::icon

Testcases:
adp_parse_tags
Source code:
    set styleAtt [expr {$style ne "" ? "style='$style'" : ""}]
    if {$iconset eq ""} {
        set iconset [::template::iconset]
    }

    if {[dict exists $::template::icon::map $iconset $name]} {
        set name [dict get $::template::icon::map $iconset $name]
    }
    set firstchar [string range $name 0 0]
    if {$firstchar eq "/"} {
        set iconset default
    } elseif {$name eq ""} {
        set iconset text
    } elseif {![string match {[a-z@]} $firstchar]} {
        set iconset text
        set alt $name
    }
    set _class [expr {$class ne "" ? $class" : ""} ]
    set title [ns_quotehtml $title]
    set cmd ""
    switch $iconset {
        "glyphicons" {
            set template {<span class='glyphicon glyphicon-$name$_class' title='$title' aria-hidden='true' $styleAtt></span>}
        }
        "bootstrap-icons" {
            set cmd {template::head::add_css -href urn:ad:css:bootstrap-icons}
            set template {<i class='bi bi-$name$_class' title='$title' aria-hidden='true' $styleAtt></i>}
        }
        "fa-icons" {
            set cmd {template::head::add_css -href urn:ad:css:fa-icons}
            set template {<i class='$name$_class' title='$title' aria-hidden='true' $styleAtt></i>}
        }
        "text" {
            if {$alt eq ""} {set alt $title}
            set template {<span class='$class' title='$title$styleAtt>$alt</span>}
        }
        default {
            #
            # When "title" is a message key, and it is used e.g. in
            # the "title" and "alt" fields, then the edit icon is
            # displayed twice in TRN mode, which look like a bug. So,
            # don't set alt per default to the message key, when it
            # looks like a message key... Or maybe better, force the
            # user to set the "alt" attribute.
            #
            #if {$alt eq "" && [string first "#" $title] == -1} {set alt $title}
            set template {<img class='$class' src='$name' height='16' width='16' title='$title' alt='$alt' style='border:0; $styleAtt'>}
        }
    }
    if {$invisible_p} {
        set template "<span style='visibility:hidden;'>$template</span>"
    }
    #ns_log notice "RETURN  HTML [subst -nocommands $template] cmd $cmd]"
    return [list HTML [subst -nocommands $template] cmd $cmd]
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: