Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

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

by skx (Parson)
on Dec 09, 2007 at 14:10 UTC ( #655956=note: print w/ replies, xml ) Need Help??


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

For my use case I don't know in advance which items to set in the header and which in the page, so this solution doesn't really scale past the small example. (Much like moving the title as suggested by ww initially failed to solve the general problem).

Steve
--


Comment on Re^2: Abstracting away layout details when using large HTML::Template-based sites?
Re^3: Abstracting away layout details when using large HTML::Template-based sites?
by wfsp (Abbot) on Dec 09, 2007 at 14:50 UTC
    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. :-)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (11)
As of 2014-07-30 17:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (237 votes), past polls