Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Control break with Template::Toolkit

by choroba (Cardinal)
on Nov 13, 2019 at 13:05 UTC ( [id://11108626]=note: print w/replies, xml ) Need Help??


in reply to Control break with Template::Toolkit

It's possible, but I'm not sure the template is the best place to put logic into:
#!/usr/bin/perl use warnings; use strict; use Template; my $template = 'Template'->new; my @reclist = ([1, 2, 'A', 4], [3, 4, 'A', 5], [5, 5, 'B', 2], [6, 2, 'B', 3], [1, 2, 'C', 2], [2, 3, 'C', 2], [1, 3, 'C', 1]); $template->process(\( join "", <DATA>), {reclist => \@reclist}); __DATA__ [% lastcat = "" %] [% FOREACH catrec IN reclist %] [% IF lastcat != catrec.2 %][% catrec.2 %][% lastcat = catrec.2 %][ +% END %] [% FOREACH rec IN catrec %] [% rec %] [% END %] [% END %]
map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^2: Control break with Template::Toolkit
by haj (Vicar) on Nov 14, 2019 at 01:02 UTC
    ...but I'm not sure the template is the best place to put logic into:
    MVC enthusiasts may enjoy heated debates about this, but in my opinion those doubts aren't worth their time. I'd easily argue that the desired output is a matter of data presentation and not a matter of logic, so a template is a quite appropriate place. We both have demonstrated that TT is quite capable of doing the transformation :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11108626]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (9)
As of 2024-04-23 18:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found