Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
go ahead... be a heretic
 
PerlMonks  

Re: Template Toolkit 2 strange behaviour

by Rhandom (Curate)
on Nov 17, 2011 at 17:42 UTC ( #938654=note: print w/ replies, xml ) Need Help??


in reply to Template Toolkit 2 strange behaviour

Template::Alloy, which should be a drop in replacement for Template::Tookit, has a configuration option called CALL_CONTEXT that can be set to one of smart (default), item, or list. There are many ways you can change the context you call in, you can set the global CALL_CONTEXT option during new, you can set it locally using a [% CONFIG CALL_CONTEXT => "list" %] inside your template, or you can use the @() and $() context specifiers (as in [% results = @( myobj.mymethod() ) %]).

The following is a table of what is returned in each context copied from the Template::Alloy pod.

       return values      smart context   list context    item context
       -------------      -------------   ------------    ------------
    A   'foo'              'foo'           'foo'         'foo'
    B   undef              undef           undef         undef
    C   (no return value)  undef           []              undef
    D   (7)                7               7             7
    E   (7,8,9)            7,8,9         7,8,9         9
    F   @a = (7)           7               7             1
    G   @a = (7,8,9)       7,8,9         7,8,9         3
    H   ({b=>"c"})         {b=>"c"}        {b=>"c"}      {b=>"c"}
    I   (1)              1             [1]           1
    J   (1,2)          [1,2]       [1,2]       2
    K   7,8,9            7,8,9         [7,8,9]       7,8,9
    L   (undef, "foo")     die "foo"       undef, "foo"  "foo"
    M   wantarray?1:0      1               1             0

Disclaimer: I am the author.

my @a=qw(random brilliant braindead); print $a[rand(@a)];


Comment on Re: Template Toolkit 2 strange behaviour
Select or Download Code
Re^2: Template Toolkit 2 strange behaviour
by Aramis (Initiate) on Nov 17, 2011 at 18:59 UTC
    Thanks for your recommendation, I had already checked the reviews and your module at CPAN. I will try it.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://938654]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2014-04-19 08:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (478 votes), past polls