http://www.perlmonks.org?node_id=1051886

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?

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