in reply to Re: Effective ways to 'write' html.
in thread Effective ways to 'write' html.

Here's the problem I have with the templating systems. They're fine if you want to remove simple HTML from simple perl, but if you have a very complex HTML display (ie. things get printed several different ways depending on the data you have or don't have) or you have a lot of data, you end up with either a lot of data being stored in memory before it's sent off to the template or you end up with really complicated templates that are no easier to manage than their perl counterparts, and are even more confusing to the graphical designers who work on them.

Let's take, for example, a database pull that prints out entries grouped by day. Let's say we do this for a month, and there's a fairly good number of entries. If you're using DBI, all you have to do is just loop over your rows, printing out the data and, if you've come upon a new day, possibly a date header. However, with templates, you can't do this. You have to read all the data in, process it into its day and entry groups, and then pass it off to the template.

What would make life a whole lot easier is if I could move all my HTML strings out into one file where the strings are named or identified somehow, then print those named (and processed, if they contain variable subs) strings. Then I remove the HTML from my script without losing any of the very clean, efficient functionality of my processing.

Does anyone know of any modules that do that? It's not really a 'template', so to speak, but a connection of named lines.

  • Comment on Re: Re: Effective ways to 'write' html.

Replies are listed 'Best First'.
Re: Re: Re: Effective ways to 'write' html.
by davorg (Chancellor) on Dec 19, 2000 at 18:47 UTC

    Actually, your database example wouldn't be a problem with the Template Toolkit. The TT comes with a number of 'plugins' that make interacting with various Perl features much easier. One of these is the DBI plugin.

    What you would do is pass into the template, either the SQL to be executed or (more likely) some data to be used in the where clause of your SQL. The DBI plugin will connect to the database, execute the SQL and process the rows one at a time. At no time do you need to have all of the data in memory at once.

    --
    <http://www.dave.org.uk>

    "Perl makes the fun jobs fun
    and the boring jobs bearable" - me

      Yeah, I've seen that feature, but I thought the whole point was to remove the programming from HTML. Yes, you pass in the SQL, but the resulting template looks very much like a piece of pseudo-code with an object.method type syntax. That, to me, is an unnecessary complication. I'd like to keep that part of the programming in my program and not shop it out to the template, just like I'd like to keep the HTML part of my template out of my code.

      I think TT is fine piece of coding and good for some things, but it's not quite the sort of template I'm looking for.