in reply to Abstracting away layout details when using large HTML::Template-based sites?
Load the title param into $page before you load $page->output into $layout
Add a little more abstraction and feel even more pleased (possibly). :-)
output:#!/usr/bin/perl use strict; use warnings; use Data::Dumper; $Data::Dumper::Indent = 1; $Data::Dumper::Sortkeys = 1; use HTML::Template; # # Load the layout and a stub page of "content" # my $layout = HTML::Template->new( filename => "layout.template" ); my $page = HTML::Template->new( filename => "page.inc" ); $page->param( title => "STEVE"); # <-- new line # # Insert the body into the layout template # $layout->param( page => $page->output() ); # # Now setup the title # $layout->param( title => "STEVE" ); print $layout->output();
update:<html> <head> <title>STEVE</title> </head> <body> <h2>STEVE</h2> <p>Imagine content here ..</p> </body> </html>
Add a little more abstraction and feel even more pleased (possibly). :-)
#!/usr/bin/perl use strict; use warnings; use HTML::Template; my $page_params = { title => "STEVE" }; my $layout_params = { title => "STEVE", page => page($page_params), }; my $layout = HTML::Template->new( filename => "layout.template" ); $layout->param($layout_params); print $layout->output(); sub page { my ($args) = @_; my $page = HTML::Template->new( filename => "page.inc" ); $page->param($args); return $page->output; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Abstracting away layout details when using large HTML::Template-based sites?
by skx (Parson) on Dec 09, 2007 at 14:10 UTC | |
by wfsp (Abbot) on Dec 09, 2007 at 14:50 UTC |
In Section
Seekers of Perl Wisdom