NAME

Top Close Open

Template:TT3::Element::Sigil::Item - element representing the $ sigil

DESCRIPTION

Top Close Open

Element for the scalar item sigil $. This is used to denote variables where a filename, keyword, bareword, or other token would be expected.

For example, if you happen to have a variable called fill, you wouldn't normally be able to access it because it's a reserved keyword in TT3. By adding a $ prefix, you're indicating that it's a variable you're after.

[% $fill %]           # variable, not a keyword

The same rule applies for calling object methods or accessing elements in a hash array or list. We would usually expect to find a bareword or number following a dot operator. If the item on the left of the dot is an object then the name on the right is that of a method. If it's a hash reference then the name on the right is that of an item in the hash array. If it's a list then the number on the right is the index of a particular item in the list. The name on the right can also be that of a virtual method for all data types.

[% iterator.first %]            # object method
[% user.name %]                 # hash item
[% list.0 %]                    # list reference

[% user.keys %]                 # hash virtual method
[% list.first %]                # list virtual method

If you put a $ in front of the item on the right then it will be treated as a variable.

    [% n = 0 %]
    [% list.$n %]                   # same as [% list.0 %]

    [% key = 'fullname' %]
    [% user.$key %]                 # same as [% user.fullname %]

The same rule applies in double quoted strings. If it starts with a $ then it's variable reference.

[% "Hello $name" %]

The $ sigil can also be used to force scalar context on the expression on its right. Scalar context is the default in TT3 so it is rarely required. I can only think of one (highly contrived) example where you might need to use it.

METHODS

Top Close Open

This module implements the following methods in addition to those inherited from the Template::TT3::Element::Sigil , Template::TT3::Element , Template::TT3::Base and Badger::Base base classes.

text()

Top Close Open

value()

Top Close Open

values()

Top Close Open

An alias to value() .

AUTHOR

Top Close Open

Andy Wardley http://wardley.org

COPYRIGHT

Top Close Open

Copyright (C) 1996-2009 Andy Wardley. All Rights Reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


http://tt3.template-toolkit.org/docs/Template/TT3/Element/Sigil/Item.pm last modified 2009-12-17 20:06:49