On 17/5/09 01:39, Ralph wrote:
> The tutorial examples seem to assume a one-to-one correspondence between
> template pages and output pages. What I'm after is being able to use a
> single template page, and a data file, to generate a separate html page
> for each name in the data file.
Hi Ralph,
You can use the Datafile plugin to load in the data, as long as you don't
mind adding a signature to the first line to tell TT what to call each field.
If you've just got one name per line and no other info then simply add "name"
as the first line in the file
e.g.
name <--- first line defines field names
Andy
Bob
Charlie
Then you can read the names in like so:
[% USE people = Datafile('names');
FOREACH person IN people;
"Hello $person.name\n";
END;
%]
Here's the relevant pages:
http://tt2.org/docs/manual/Plugins.html#section_Datafile
http://tt2.org/docs/modules/Template/Plugin/Datafile.html
Then you can use the redirect filter to generate a separate page for
each user:
http://tt2.org/docs/manual/Filters.html#section_redirect_file_options_
Put it all together and it looks something like this:
[% USE people = Datafile('names');
FOREACH person IN people;
FILTER redirect("${person.name}.html"); %]
Hello [% person.name %]
[% END;
END;
%]
HTH
A
_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates