Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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

by wfsp (Abbot)
on Dec 09, 2007 at 14:50 UTC ( #655962=note: print w/ replies, xml ) Need Help??


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

HTML::Template puts together html very nicely. Everything else should be done by your script. I think you are trying to get the template to do too much.

Your "content will be coming from... a database" so you could add a field which specifies "which items to set in the header and which in the page" or alternatively put that information in your script/config file i.e. one way or another, make a table.

#!/usr/bin/perl use strict; use warnings; my %config = ( page => { tmpl => q{page.tmpl}, params => [qw{title param1 param2}], }, layout => { tmpl => q{layout.tmpl}, params => [qw{title param3 param4}], }, ); my %all_params = ( title => q{title}, param1 => q{param1}, param2 => q{param2}, param3 => q{param3}, param4 => q{param4}, ); my %page_params = map {$_ => $all_params{$_}} @{$config{page}->{para +ms}}; my %layout_params = map {$_ => $all_params{$_}} @{$config{layout}->{p +arams}}; print Dumper \%page_params; print Dumper \%layout_params;
output:
$VAR1 = { 'param2' => 'param2', 'title' => 'title', 'param1' => 'param1' }; $VAR1 = { 'param4' => 'param4', 'param3' => 'param3', 'title' => 'title' };
Everything is in your code where, imo, it should be and then let HTML::Template do what it is very good at, whacking out nice HTML.

Using a filter on a template is, imo, rather missing the point but ymmv.

Perl data structures are the best thing since sliced bread, let Perl take the load. :-)


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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2015-08-01 00:31 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 (285 votes), past polls