Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Template Toolkit WRAPPER variations

by tachyon-II (Hermit)
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
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 (Monsignor) 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 (Hermit) 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 chilling in the Monastery: (6)
As of 2014-07-11 23:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (236 votes), past polls