Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

template toolkit question -- metadata

by madison.sacd (Novice)
on May 11, 2007 at 06:29 UTC ( #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, 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 %] / [% %] / [% 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 -


    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?

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2021-12-06 21:56 GMT
Find Nodes?
    Voting Booth?
    R or B?

    Results (33 votes). Check out past polls.