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

Template Toolkit WRAPPER variations

by tachyon-II (Chaplain)
on Sep 02, 2013 at 05:08 UTC ( #1051886=perlquestion: print w/ replies, xml ) Need Help??
tachyon-II has asked for the wisdom of the Perl Monks concerning the following question:

With Template Toolkit I can do this:
[% WRAPPER wrapper.html %] ... [% END %]

What I want to do is this

In perl $c->stash->{popup} = 1 In template [% WRAPPER popup ? wrapper_popup.html : wrapper.html %]

That can't be parsed, so I tried

[% wrapper = popup ? wrapper_popup.html : wrapper.html %] [% WRAPPER wrapper %]

But "wrapper" is interpreted as a string literal.

Question: Is their any way to make WRAPPER directive interpolate a variable?

Comment on Template Toolkit WRAPPER variations
Select or Download Code
Replies are listed 'Best First'.
Re: Template Toolkit WRAPPER variations
by Anonymous Monk on Sep 02, 2013 at 07:22 UTC

    Question: Is their any way to make WRAPPER directive interpolate a variable?

    Give it a $variable

    [%# USAGE tpage --define news_id=all wrapper-macro.tt tpage wrapper-macro.tt -%] [%- BLOCK link -%] <a href="[% action | uri %]/[% newsitem | uri %]">[% content | html %] +</a> [%- END -%] [% SET vink = ( 1 < 2 ) ? 'link' : 'knil'; PROCESS $vink action = 'readnews' newsitem='some' content='Read +Some'; %] [% WRAPPER link action = "readnews" newsitem = news_id %] Read More ... [% END %]
    $ tpage wrapper-macro.tt <a href="readnews/some">Read Some</a> <a href="readnews/"> Read More ... </a> $ tpage --define news_id=all wrapper-macro.tt <a href="readnews/some">Read Some</a> <a href="readnews/all"> Read More ... </a>
Re: Template Toolkit WRAPPER variations
by sundialsvc4 (Abbot) on Sep 02, 2013 at 13:35 UTC

    Anonymous Monk gets two upvotes.

    In code I have seen, you find, say:   [%WRAPPER wrap/dialog.tt mode="popup"%].

    Then, within that wrapper file:

    [%IF mode == "popup" %] ... directives for a popup ... [% ELSE %] ... directives for anything else (i.e. "mode" not specified) ... [% END %]

Re: Template Toolkit WRAPPER variations
by tachyon-II (Chaplain) on Dec 10, 2013 at 11:43 UTC

    If anyone is looking this does what was desired

    $c->stash->{popup} = 1 [% wrapper = popup ? 'wrapper_popup.html' : 'wrapper_new.html' %] [% WRAPPER $wrapper %]

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1051886]
Approved by NetWallah
Front-paged by NetWallah
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (13)
As of 2015-07-29 13:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (263 votes), past polls