Be careful when mocking Template::Toolkit. It's quite powerful, in fact more powerful than it should be - it's a Turing-complete language.
The whole idea of Template (or any comparable renderer, say Text::Xslate, dozens of them) is the separation of logic from presentation - but with a very flexible presentation layer. You just give the templating engine a template and a hash of values - and the engine does the rest. Templates are much easier to edit than general-purpose code. I'm never ever coming back to $form->addElement("foo")->addValue("bar");
Dancer example shows only variable substitution for simplicity, but Template can do way more than that.
- Conditionals with [% IF foo == bar %]...[% END %];
- looping with [% WHILE cond %]...[% END %];
- iterating over data [% FOREACH item IN list %] * [% item | html %];[% END %];
- sanitizing/escaping/trimming strings [% GET username | html %];
- filtering them through predefined perl functions [% FILTER myfunc %]some text here[% END %];
- , inclusion of external files (say headers/footers) [% PROCESS file %] or [% INCLUDE file %] and - last but not least -
- defining your own blocks to avoid boilerplate/repetitions: [% BLOCK foo %]...[% END %] and then [% PROCESS foo option="value" %]
See Template documentation for more examples. I didn't have time to google a comprehensive portfolio though.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.