Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Abstracting away layout details when using large HTML::Template-based sites?

by Rhandom (Curate)
on Dec 10, 2007 at 16:24 UTC ( #656164=note: print w/ replies, xml ) Need Help??


in reply to Abstracting away layout details when using large HTML::Template-based sites?

Template::Alloy also provides ways to do what you want. In addition to supporting all of HTML::Template and HTML::Template::Expr, it also allows for using TT tags in your templates as well - and as a plus Template::Alloy is faster than HTML::Template.

The following code shows inserting dynamic page content in two ways: passing a variable to the PROCESS directive, and the second way is passing raw text to eval (eval simply uses the current template object and parses the text that is passed as a template - if normal cache options are set, this method can still be very fast).

use Template::Alloy; use POSIX qw(tmpnam); my $file1 = tmpnam; my $file2 = tmpnam; END { unlink $file1 }; END { unlink $file2 }; if (open my $fh, ">", $file1) { print $fh "I am file1 ($file1). title = (<TMPL_VAR name=title>). page = (<TMPL_VAR name=page>). ------------------ <TMPL_PROCESS \$page> ------------------ <TMPL_GET page3.eval> "; close $fh; } if (open my $fh2, ">", $file2) { print $fh2 "I am file2 ($file1). title = (<TMPL_VAR name=title>). "; close $fh2; } my $ht = Template::Alloy->new(filename => $file1, absolute => 1); $ht->param(title => 'The title'); $ht->param(page => $file2); $ht->param(page3 => sub { "This is a dynamically included string.\ntit +le = (<TMPL_VAR name=title>)\n"}); print $ht->output; __END__ prints I am file1 (/tmp/filessyE4j). title = (The title). page = (/tmp/filez6O6TO). ------------------ I am file2 (/tmp/filessyE4j). title = (The title). ------------------ This is a dynamically included string. title = (The title)

my @a=qw(random brilliant braindead); print $a[rand(@a)];


Comment on Re: Abstracting away layout details when using large HTML::Template-based sites?
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (11)
As of 2015-07-31 11:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (276 votes), past polls