METHODS

Top Close Open

init_tagset()

Top Close Open

We allow tag sets to be specified using hash refs for simple mapping by name where the order of tags isn't important.

$TAGS = { inline => { ... }, outline => { ... }, etc }

Or they can be defined using list refs for those times when the order of tags matching is important. For example, if you have a '$' tag for embedding "naked" variables in the template text then you (probably) also want a '\$' tag (or a more generic '\' escaping tag) to allow the user to escape dollar signs that shouldn't be interpreted as variables. The scanner will *usually* do the right thing by matching tokens in order of length from longest to shortest. So '\$' will get (correctly) matched before '$'. However, in the case of '$' vs '\' either could come first (due to the unpredictable order of hash array contents).

In those cases it's better to be explicit and specify the tags using a list reference. That avoids any ambiguity.

$TAGS = [ inline => { ... }, outline => { ... } ]

Subsequent entries will not be added to the order. However, the values they define will replace those of the earlier occurence. For example:

$TAGS = [ 
    inline  => { ... }, 
    outline => { ... } 
    inline  => 0,
]

The above ends up being equivalent to:

$TAGS = [ 
    inline  => 0, 
    outline => { ... } 
]

The original order is preserved, but the latter value supersedes the earlier one. In this example, the end result is that the inline tag has been disabled. Note that we construct the $TAGS list from a number of sources. So the module may define the first 'inline' tags, but the user supersedes it by passing the 'inline => 0' parameter.


http://tt3.template-toolkit.org/docs/Template/TT3/Tagset.pm last modified 2009-12-23 14:57:14