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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I may be missing something here, but this seems to work, at the price of (partially) re-mixing content and layout. Further, from the description of your project, I'm guessing that you will be taking the title from the command line or yet another file, hence the new var, $input.

#!/usr/bin/perl -w # 655823 use strict; use warnings; use HTML::Template; # new; replace to use from ARGV or some other project file my $input = "STEVE"; my $layout = HTML::Template->new( filename => "layout.tmpl" ); my $page = HTML::Template->new( filename => "page.inc" ); $layout->param( page => $page->output() ); # Now setup title with $input, rather than hardcoding $layout->param( title => "$input" ); # spit out the page print $layout->output();

When layout.tmpl is modified by moving the line <h2>...</h2> from page.inc, to line 6 here:

<html> <head> <title><!-- tmpl_var name='title' --></title> </head> <body> <h2><!-- tmpl_var name='title' --></h2> <!-- tmpl_var name='page' --> </body> </html>

after which, page.inc becomes simply

<p>Imagine content here ..</p>

and the output is:

<html> <head> <title>STEVE</title> </head> <body> <h2>STEVE</h2> <p>Imagine content here ..</p> </body> </html>

This leaves various issues, however; the most obvious being any case in which your page.inc was more complex -- eg, has body content intended to appear before the <h2...> pair. That's because this writer tackled the question only to begin acquiring more than my current, mimimal knowledge of HTML::Template.


In reply to Re: Abstracting away layout details when using large HTML::Template-based sites? by ww
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-23 20:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found