hello monks, i'm using HTML::Template and TMPL_LOOP. i think i don't need a more complex templating system, there are only two little things at the moment i miss with this module. suppose i have data like:
my $data = { name => 'name', id => 1, categories => [ { id => 1, title => 'projects', ...}, { id => 2, title => 'index', ...}, ], };
and the template:
<TMPL_VAR NAME=ID>: <TMPL_VAR NAME=NAME><br> <TMPL_LOOP NAME=CATEGORIES> <TMPL_VAR NAME=ID>/<TMPL_VAR NAME=TITLE> | </TMPL_LOOP>
then it outputs:
1: name<br> 1/projects | 2/index |
first thing is: i only want one pipe | between the items, like in perl join " | ", @$items.
do you know any way to do that with HTML::Template?

the second thing: i'd like to be able to control the order of the items from the template (reason: the code is part of a kind of framework or CMS, and i don't want to hardcode it).

what i've done for the second problem:

i added a tag: <TMPL_VAR NAME=SET_REVERSE> which has to be inside of the loop. before i generate the template i use the query()-function to detect if the tag SET_REVERSE is in that loop, and then i reverse the list.
foreach my $key (keys %$result) { if ($self->template()->query( name => $key) eq 'LOOP') { if ($self->template()->query( name => [$key, 'SET_REVE +RSE'])) { @{$result->{$key}} = reverse @{$result->{$key} +}; } } }
this seems to work fine (i'm working only with one level deep data structures, fortunately). but it seems unelegant. do i need a different templating system? anyone can recommend one? or does this look reasonable to you?
thanks for any comments...

In reply to HTML::Template - loop order by tinita

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.