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

sh1tn has asked for the wisdom of the Perl Monks concerning the following question:

Fellow Monks, I am trying to use regular expressions in .tmpl file:
<TMPL_IF my_var =~ /some string/>
Is this possible?
Thank you.


Replies are listed 'Best First'.
Re: HTML::Template regular expression usage
by wfsp (Abbot) on Feb 18, 2008 at 13:06 UTC
    Is this possible?
    No.

    From the docs

    ...it enforces an important divide - design and programming.
    The idea behind HTML::Template is that what you are trying to do is to put 'programming' in your template.

    Why can't you put that regex in your param, something like

    my $flag; if (my_var =~ /some string/){ $flag++; } my $param = { flag => $flag, };
    <TMPL_IF flag>
    imo, this restriction is a good thing. It forces you to separate your logic from your presentation, and, I think, both your code and your templates are better for it. Another benifit is that H::T is a fast, easy to use, lightweight solution for most needs.

    Perhaps consider something like Template::Toolkit if H::T is too restrictive for your needs.

    updated: fixed link