tinita has asked for the wisdom of the Perl Monks concerning the following question:
and the template:my $data = { name => 'name', id => 1, categories => [ { id => 1, title => 'projects', ...}, { id => 2, title => 'index', ...}, ], };
then it outputs:<TMPL_VAR NAME=ID>: <TMPL_VAR NAME=NAME><br> <TMPL_LOOP NAME=CATEGORIES> <TMPL_VAR NAME=ID>/<TMPL_VAR NAME=TITLE> | </TMPL_LOOP>
first thing is: i only want one pipe | between the items, like in perl join " | ", @$items.1: name<br> 1/projects | 2/index |
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:
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?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} +}; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: HTML::Template - loop order
by ccn (Vicar) on Aug 03, 2004 at 18:44 UTC | |
by tinita (Parson) on Aug 03, 2004 at 18:49 UTC | |
by ccn (Vicar) on Aug 03, 2004 at 19:02 UTC | |
by tinita (Parson) on Aug 04, 2004 at 07:52 UTC | |
|
Re: HTML::Template - loop order
by waswas-fng (Curate) on Aug 03, 2004 at 21:29 UTC | |
by tinita (Parson) on Aug 04, 2004 at 08:02 UTC | |
|
Re: HTML::Template - loop order
by Aristotle (Chancellor) on Aug 03, 2004 at 18:44 UTC | |
by tinita (Parson) on Aug 03, 2004 at 18:51 UTC | |
|
Re: HTML::Template - loop order
by antirice (Priest) on Aug 03, 2004 at 18:59 UTC |