Hi

I'm guesings from the tag syntax that you're using HTML::Template. In which case, no, you can't put a tmpl_var inside an include. This is probably not a bad thing from a security point of view, as if it were possible, it'd be temptingly easy to do something like:

my $tpl = HTML::Template->new(); my $q = CGI->new(); $tpl->param( 'file' => $q->param('file') ); # Then in your template <tmpl_include name="<tmpl_var name=file>">

Which is all nice, until someone requests the page with /cgi-bin/myscript.pl?foo=bar&file=/path/to/my/secrets.

To work round it, I'd suggest using the tmpl_if constructs to include different specified alternatives depending on a variable's values:

<tmpl_if name="foo"> <tmpl_include name="foo.inc"> </tmpl_if> <tmpl_if name="bar"> <tmpl_include name="bar.inc"> </tmpl_if>

IIRC, the way this is implemented means that it can be wasteful if you have lots of includes within conditionals, as all the includes get opened at the parse stage. If you have SO many alternatives that this is unwieldy, then maybe you need to rethink how your application is working - maybe what you are trying to include is data that should, in fact, be passed into the template like other params? Or maybe HTML::Template's filter facilites might help?

cheers
ViceRaid


In reply to Re: question on tmpl_include by ViceRaid
in thread question on tmpl_include by kiat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.