in reply to Learning Template::Toolkit - have I understood?

1. RE: Dynamic generation - yes, that's certainly one option I'm considering. I like the idea of pre-generation of static html pages for the clarity, the server load. But this requirement for authors to launch a generation routine each time they make a change is a stumbling block. One possible compromise would be a secure author's control panel page with a "Generate!" button that launches a cgi script to do all the work. It's not bad.

2. RE: ttree recursion vs. content recursion - From the tutorial suggested above, I note: DYNAMIC CONTENT GENERATION VIA CGI SCRIPT

#!/usr/bin/perl -w use strict; use Template; my $file = 'src/greeting.html'; my $vars = { message => "Hello World\n" }; my $template = Template->new(); $template->process($file, $vars) || die "Template process failed: ", $template->error(), "\n";
Which I believe implies that although TT has ttree to automatically drill down through a hierarchy to find and process a whack of templates, if I have only one template and a whack of content files, I have to do the recursion work myself. To my mind, this seems a little backwards, since a large template-driven site is rarely going to be the first case, and much more commonly going to be the second case. No?

So, OK, I make my template with the appropriate INCLUDES, etc. Then I have to write a script that travels my website structure looking for content files (probably designated by an extension), and merging them with the template. To be honest, I could have done that myself with a couple of custom markers in the html files and a little routine to scour the pages for the markers, parse out the tag and shunt to a corresponding insertion routine. But I guess the moduloe has the advantage of lots of other functionality for the future...




Forget that fear of gravity,
Get a little savagery in your life.

Replies are listed 'Best First'.
Re^2: Learning Template::Toolkit - have I understood?
by perrin (Chancellor) on Aug 30, 2006 at 17:07 UTC
    One way to deal with re-generation is to use a cron to generate the whole thing (or just changes) every 15 minutes. Then you can tell people their changes will be live in 15 minutes.

    It doesn't like ttree is a good fit for you though. Just write your own script that grabs all the content and calls TT directly. It's not hard. There's no reason to use ttree if it doesn't obviously fit your model.

Re^2: Learning Template::Toolkit - have I understood?
by Asim (Hermit) on Aug 30, 2006 at 14:57 UTC
    I like the idea of pre-generation of static html pages for the clarity, the server load.

    You might consider Template caching (see "Caching and Compiling Options") as a easy solution for that issue.

    To my mind, this seems a little backwards, since a large template-driven site is rarely going to be the first case, and much more commonly going to be the second case. No?

    If you're converting to TT from a HTML-only design, yes, it's backwards. And that's not something TT was designed for; it's mostly built for ground-up design with TT in mind.

    So, first off, you can indicate that TT "scoop up" .html files, or any other content. The INCLUDE_PATH option will contain a list of directories to look in, and you can write a quickie "generator" for it to recurse through your directory structure if you'd like, or manually list the directories; it's your choice. Make a "base" template, use the WRAPPER option, and then the "sub-templates" with the content get slugged in via the [% content %] tag. I strongly recommend skimming the various parts of the Template Manual; there is a LOT of power to the Template Toolkit that's not obvious, and it not "typical usage", as you've surmised.

    Does that help?

    ----Asim, known to some as Woodrow.