Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Well, HTML::Template is not going to make your database searching any easier, but it will allow you to use abstraction techniques on HTML. For example, i like to use a 'skeleton' template that encapsulates the header, footer, and main content for a site:
<html> <head> <title><tmpl_var title></title> </head> <body> <tmpl_include name="header.html"> <tmpl_var CONTENT> <tmpl_include name="footer.html"> </body> </html>
Now, that was just an example ... i don't always use that format, but i hope you get the picture. The idea is that you break up the "elements" of the web site into their own files. Say you have a menu bar on the side. You can abstract the HTML into it's own file and then simply include that file when you need it. As long as code that populates the params of the HTML::Template object passes the parameters that 'widget' needs, all is well. Here is a complete example you can play with:

The CGI script:
#!/usr/bin/perl -T use strict; use warnings; use CGI qw(header); use HTML::Template; my $tmpl = HTML::Template->new(filename => 'skeleton.tmpl'); $tmpl->param( title => "I AM JACK's HTML TITLE", CONTENT => "I AM JACK's HTML CONTENT", menu => [ {item => "JACK's LIVER", url => 'liver.html'}, {item => "JACK's SPLEEN", url => 'spleen.html'}, {item => "JACK's SPRAT", url => 'sprat.html'}, ], ); print header, $tmpl->output;
The skeleton template:
<html> <head> <title><tmpl_var title></title> </head> <body> <tmpl_include header.tmpl> <tmpl_var CONTENT> <tmpl_include footer.tmpl> </body> </html>
The header template:
<h1>hello world</h2> <tmpl_include menu.tmpl>
The footer template:
<h1>goodbye world</h1>
And finally, the menu template:
<ol> <tmpl_loop menu> <li><a href="<tmpl_var url>"><tmpl_var item></a></li> </tmpl_loop menu> </ol>

One last item. A question for you. What is the difference between two forms - one form adds a new record, the other form edits an existing record? What is really the only difference? The first form does not have an id - the second does. So, if there is no id present, then the user is adding a new record. If there is, then they are editting an existing record. It is really not very hard to abstract this into 3 templates: 2 skeletons (one for edit, one for add) and a template that contains the form elements. I leave this as an exercise. :)

Oh, and remember, sometimes it is more trouble than it is worth to get as abstract as you possible can. You might wind up making your interface so general that no one can easily use it anymore. :/

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

In reply to 3Re: HTML::Template - complex sites by jeffa
in thread HTML::Template by defyance

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: (7)
As of 2024-03-28 09:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found