Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: mini-languages for MVC view/controller manipulation

by hardburn (Abbot)
on Dec 27, 2004 at 15:18 UTC ( [id://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.

Replies are listed 'Best First'.
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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://417557]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2024-04-19 06:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found