Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

HTML::Template regular expression usage

by sh1tn (Priest)
on Feb 18, 2008 at 12:08 UTC ( #668513=perlquestion: print w/replies, xml ) Need Help??
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?

    From the docs 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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://668513]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (7)
As of 2018-05-24 08:01 GMT
Find Nodes?
    Voting Booth?