Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: Format and Join an Array in a Template

by mscharrer (Hermit)
on Jun 20, 2009 at 09:32 UTC ( [id://773223]=note: print w/replies, xml ) Need Help??


in reply to Re: Format and Join an Array in a Template
in thread Format and Join an Array in a Template

Ah, thanks! Both look quite interesting. I will check them out. Template seems to be quite powerful.
  • Comment on Re^2: Format and Join an Array in a Template

Replies are listed 'Best First'.
Re^3: Format and Join an Array in a Template
by Your Mother (Archbishop) on Jun 20, 2009 at 19:49 UTC

    Great. I adore TT and this example goes to the root of why and why I break from the View purists who say TT is a disaster and you should use something like HTML::Template. These simple loop controls can solve many common display logic problems.

    TT can do just about anything. Beware of moving too much into it (it can write files, run macros, run plain Perl, do recursion, etc, etc, etc). If you want a ton of code in templates, Mason is probably the right choice. TT lets you separate and plugin really well though so you can do your own methods and filters, for example, without writing anything but glue code; The Right Way to Do It™. Just another example-

    use warnings; use strict; use Template; use Lingua::EN::Numbers::Ordinate "ordinate"; my %config = ( FILTERS => { ordinal => sub { ordinate($_[0]) }, ordinal_html => sub { my $ord = ordinate($_[0]); $ord =~ s,(\D\D)\z,<sup>$1</sup>,; return $ord; } } ); my $tt2 = Template->new(\%config); $tt2->process(\*DATA, { numbers => [ 0 .. 121 ] }) or die $tt2->error; __DATA__ [% FOR i IN numbers %] Plain: [% i | ordinal %] -- HTML: [% i | ordinal_html %] [%-END %]

    I'd also point you toward Template::Alloy. It's a well behaved implementation of the TT2(3) syntax with a few improvements and supports several other template types. I've used it on my last couple of projects and haven't hit any reasons to go back.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-04-19 07:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found