Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

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)];

Replies are listed 'Best First'.
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?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2020-09-21 13:58 GMT
Find Nodes?
    Voting Booth?
    If at first I donít succeed, I Ö

    Results (126 votes). Check out past polls.