Hello all,

I have a CGI::Application webapp in which I would like to dynamically include template file names based on context (specifically, which of several policies might apply to the end user).

Taking cues from the sources listed below, this seemed a trivial task; create a text substitution code reference and feed that to the filter option. However, I cannot get it to work, even after stripping down to the most basic test case.

Sources

My template test file (magic-tmpl.html):

<p>Where's the magic?</p> !!!blargle!!!

My test code:

#!/usr/bin/perl use Modern::Perl; use HTML::Template; # This is the part that would be context-driven, if it worked... my $policy_file = 'test-policy.html'; my $magic = sub { my $textref = shift; $textref =~ s/!!!blargle!!!/<tmpl_include $policy_file>/g; }; my $t = HTML::Template->new( filename => '/web/filter/data/magic-tmpl.html', filter => $magic ); say $t->output; __END__ Produces: <p>Where's the magic?</p> !!!blargle!!!

Obviously, the desired substitution is not occuring. If anyone can help me locate the appropriate fairy dust for this kind of magic, I should be very grateful. I am hoping for a solution within CGI::Application and HTML::Template, but would consider other frameworks as needed. Thank you for your time.


In reply to Using the filter option of HTML::Template by Anonymous Monk

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.