Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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

Comment on template toolkit question -- metadata
Select or Download Code
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

Re: template toolkit question -- metadata
by Anonymous Monk on May 11, 2007 at 09:53 UTC
    type == 'B' you are using a numeric comparison as opposed to a string comparison. Try 'eq' instead of '=='. This would generally mean that it would default to false. If you change the else to an elseif type == 'C' and add another else then im pretty sure it will default to the else and not default to CD all the time. that way u can test to see if any of your comparisons are working or not ^_^

      OP knows the comparisons are working because of the debug-statements; the code is not Perl, but TemplateToolkit2 - and there was no eq in TT2 the last time I took a look (take a look for yourself)


      regards,
      tomte


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

Log In?
Username:
Password:

What's my password?
Create A New User
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? | Other CB clients
Other Users?
Others contemplating the Monastery: (11)
As of 2014-12-29 11:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (186 votes), past polls