Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: HTML::Template - complex sites

by Heidegger (Hermit)
on Mar 25, 2003 at 08:58 UTC ( [id://245628]=note: print w/replies, xml ) Need Help??

in reply to HTML::Template

I'm using the HTML::Template in my project. The examples given in the tutorials are pretty simple - one or two tables. However, if you take a normal website, it contains 2-3 menus, a few link boxes, page content, header, footer and other things. So, there is a need to break the homepage into small templates. Here we go: I have ~ 30-50 templates in my project. I'd liked to hear from othe perl monks how they deal with such situation, because I believe most of the websites are pretty complicated.

I use HTML::Template together with DBIx::Recordset at my work. As I have already noted I have ~ 30-50 templates for different entry forms and website components such like button groups. I use template includes and loops, trying to make them as abstract as possible.

I'd liked to hear if anyone is writing such modules like that loads its entries from the database and knows how to display its items using the templates. There are many components which I needed for my website and had to write myself. I believe there must be frameworks like that around, but I don't know any.

Replies are listed 'Best First'.
Re: Re: HTML::Template - complex sites
by bradcathey (Prior) on Sep 01, 2003 at 19:04 UTC
    I would like to know more about how you are doing things and what you mean by breaking the homepage into small templates.

    I am using a MySQL db to populate variables.

    Also, I'm afraid I'm using H::T to swap out large chunks of HTML, depending on whether a user is entering a new record or editing an old, avoiding using 2 templates, one for each. It's a toss-up: do you want to edit the design in 2 files or make it harder to edit the design in just one, but more complicated file? I don't know.

      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:

      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. :/


      (the triplet paradiddle with high-hat)

Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2024-04-24 04:04 GMT
Find Nodes?
    Voting Booth?

    No recent polls found