Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: mini-languages for MVC view/controller manipulation

by hardburn (Abbot)
on Dec 27, 2004 at 15:18 UTC ( #417557=note: print w/ replies, xml ) Need Help??


in reply to mini-languages for MVC view/controller manipulation

HTML::Template . . . A popular, robust, powerful mini-language templating system which also does just fine on normal text files.

IMHO, it's not suitable for normal text files because of the way it handles whitespace:

$ perl -MHTML::Template -e '$in = join "", <>; $tmpl = HTML::Template- +>new( scalarref => \$in ); print $tmpl->output;' Hi <TMPL_IF foo> <TMPL_INCLUDE foo.txt> </TMPL_IF> Hello

Which will output:

Hi Hello

The extra lines just aren't acceptable for plaintext. It's fine for HTML since whitespace is almost always ignored there.

"There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.


Comment on Re: mini-languages for MVC view/controller manipulation
Select or Download Code
Re^2: mini-languages for MVC view/controller manipulation
by simonm (Vicar) on Dec 28, 2004 at 07:44 UTC
    This doesn't seem like much of a problem; either leave the extra whitespace out of your source files, or mark the extra lines in some way and remove them before processing.

    Version one looks like this:

    Hi <TMPL_IF foo><TMPL_INCLUDE foo.txt> </TMPL_IF>Hello

    Version two looks like this:

    Hi \ <TMPL_IF foo>\ <TMPL_INCLUDE foo.txt> </TMPL_IF>\ \ Hello
    ... $in =~ s/\\\n[\t ]*//g; ...

    Doesn't this same issue apply to most templating packages, or am I missing something about why this is more of an issue for HTML::Template than the others?

      Doesn't this same issue apply to most templating packages . . . ?

      Probably. If there is anything special about H::T, it's that its default tag syntax is a bit lengthy. Compare to Text::BasicTemplate:

      Hi %if foo%include%fi% Hello

      (Note that Text::BasicTemplate doesn't have an equivilent to TMPL_INCLUDE by default, though it can call out to Perl subroutines.)

      That's a much more condensed example that, IMHO, works better for plaintext.

      "There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://417557]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2014-07-10 06:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (202 votes), past polls