Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
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. :-)


In reply to Re^3: Abstracting away layout details when using large HTML::Template-based sites? by wfsp
in thread Abstracting away layout details when using large HTML::Template-based sites? by skx

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others rifling through the Monastery: (7)
    As of 2014-08-30 20:47 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best computer themed movie is:











      Results (293 votes), past polls