Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
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.

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
Node Status?
node history
Node Type: note [id://417557]
help
Chatterbox?
[choroba]: TITS = Try It To See :-)
[LanX]: buongiorno!
[Discipulus]: buongiorno a te!
[choroba]: LanX ciao! BTW, yesterday evening I arrived home in my new car ;-)
[Discipulus]: it seems some signal is issued but only by services
[Discipulus]: which one choroba?

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2017-01-17 09:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (154 votes). Check out past polls.