Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Alternate template syntax for HTML::Template?

by BUU (Prior)
on Oct 01, 2005 at 11:37 UTC ( [id://496625]=perlquestion: print w/replies, xml ) Need Help??

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

I'm afraid this is a rather lazy question and probably not in a good way. I was having a bit of an argument on IRC the otehr day about whether or nor HTML::Template supported alternate syntax for it's template tags, beyond the basic <TMPL_> type stuff. I was taking the position that it did in fact support such things, but after reading through the docs on cpan and the associated sourceforge site, I was unable to find any hint of such thing. Did I just completely imagine this alternate syntax, or is it hiding someplace?

Replies are listed 'Best First'.
Re: Alternate template syntax for HTML::Template?
by polypompholyx (Chaplain) on Oct 01, 2005 at 12:28 UTC
    You can use <!--TMPL_VAR NAME=PARAM-->, so the code will still validate as HTML. However, this throws errors with HTMLTidy if the parameter in question is an attribute of an HTML tag (<meta name="keywords" content="<!--TMPL_VAR NAME="KEYWORDS"-->" />), so I'm not sure how much of an advantage this more verbose syntax is.
Re: Alternate template syntax for HTML::Template?
by neniro (Priest) on Oct 01, 2005 at 12:42 UTC
    If you like asp/jsp-style tags you could consider HTML::Template::Compiled which is, as nice sideeffect, about 3 times faster than the original HTML::Template. If you want templates that are valid xml/xhtml you can take a look at Petal, which is an implementation of Zopes TAL for Perl.

      Note that HTML::Template::Compiled isn't 100% compatible with HTML::Template.

      For example the following snippet of code shows errors:

      <tmpl_if name="title"> <title><!-- tmpl_var name="title" --></title> <tmpl_else> <title><!-- tmpl_var name='site_slogan' --></title> </tmpl_if>

      The error given references the second line:

      'TMPL_ELSE' does not match opening tag (if) at templates/index.templat +e line 2
      Steve
      --
        Note that HTML::Template::Compiled isn't 100% compatible with HTML::Template.

        For example the following snippet of code shows errors:

        thanks for pointing that out.
        i would still call it quite compatible (although not 100%, you're right), the above is just a bug. i'll try to repair it.

        update: fixed it, will be available soon on sourceforge.

Re: Alternate template syntax for HTML::Template?
by Cody Pendant (Prior) on Oct 01, 2005 at 13:24 UTC
    Perhaps you were thinking of this?
    vanguard_compatibility_mode - if set to 1 the module will expect to see <TMPL_VAR>s that look like %NAME% in addition to the standard syntax. Also sets die_on_bad_params => 0. If you're not at Vanguard Media trying to use an old format template don't worry about this one.


    ($_='kkvvttuu bbooppuuiiffss qqffssmm iibbddllffss')
    =~y~b-v~a-z~s; print
Re: Alternate template syntax for HTML::Template?
by eric256 (Parson) on Oct 02, 2005 at 17:45 UTC

    You are looking for the 'filter' parameter to new.

    From the documentation:

    my $filter = sub { my $text_ref = shift; $$text_ref =~ s/!!!ZAP_(.*?)!!!/<TMPL_$1>/g; }; # open zap.tmpl using the above filter my $template = HTML::Template->new( filename => 'zap.tmpl', filter => $filter);

    You would then be able to use !!!VAR name="whatever"!!! Personaly though i like something along the lines of:

    sub convert { my $text_ref = shift; $$text_ref =~ s/\[\%=(.*?)\%\]/<TMPL_VAR NAME=$1>/g; $$text_ref =~ s/\[\%\/(.*?)\%\]/<\/TMPL_$1>/g; $$text_ref =~ s/\[\%(.*?)\%\]/<TMPL_$1>/g; }

    This lets me to [%=name%] and [%if name%] [%/if%] which i like more than the default.


    ___________
    Eric Hodges

    Edit by castaway - fixed code tags

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://496625]
Approved by planetscape
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2024-03-19 10:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found