Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

template toolkit question -- metadata

by madison.sacd (Novice)
on May 11, 2007 at 06:29 UTC ( [id://614822]=perlquestion: print w/replies, xml ) Need Help??

madison.sacd has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I am trying to show different title in template.

In my controller list.pm, I assign a type variable to the template.
$c->stash->{type} = 'B';
In the template, according to the type, the metadata "title" will be assigned different value, "Book" or "CD". My problem is that I got correct debug output for each condition. However, "CD" will always be assigned to the metadata "title". In other words, when I pass type 'B' to template, the debug output shows "!!!!!!!!!!", which is correct, but the title displays "CD". Anything wrong with my code?
[% IF type == 'B'; META title = 'Book'; debug("!!!!!!!!!!"); debug(type); ELSE; debug("@@@@@@@@@@"); debug(type); META title = 'CD'; END; -%]

Replies are listed 'Best First'.
Re: template toolkit question -- metadata
by Tomte (Priest) on May 11, 2007 at 08:27 UTC

    The TT2 documentation says:

    The META directive allows simple metadata items to be defined within a template. These are evaluated when the template is parsed
    That means that the last value assigned to a META item will 'win', so to speak, as the conditional can't be and isn't evaluated during parse-time - change the order of the conditional, and the title should always display "BOOK".

    Edit: I experimented a bit with the following template

    [% SET type = "D" %] [% IF type == 'B'; META title = 'Book'; ELSIF type == 'D'; META title = 'DVD'; ELSE; META title = 'CD'; END; -%] - [% template.title %] / [% type %] / [% template.name %] / [% templa +te.modtime %] - [% META title = 'LAST' %]
    and ttree to test my hypothesis, and I seem to interpret the documentation correctly:
    - LAST / D / test.tt2 / 1178881986 -

    regards,
    tomte


    An intellectual is someone whose mind watches itself.
    -- Albert Camus

A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://614822]
Approved by bingos
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-19 01:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found