[Templates] Recursion in macros?
lmb
lars@marowsky-bree.de
Thu, 16 Jan 2003 23:37:07 +0100
Hi all,
now my MetaCache module is working quite nicely - links change the URL
automatically whereever I move the page, language icons can be set, the title
of the page is consistent across the entire site, "referenced by" lists show
up automatically when I add a link anywhere, I can query a list of pages which
have a particular attribute set etc.
(I'm doing this by generating a cache of the META data on each run of ttree,
even though this requires two runs to fully update all sites as I am
generating purely static result pages - if I would dynamically generate them
I'd just need to check them in, but that's not what I want ;-)
And I am wondering how to best generate the navigation completely
automatically. This amounts to a tree traversal; the obvious way to do this
would be a recursive macro ;-)
But I doubt that MACROs are recursion safe, are they?
The other option would be to do this in a Perl function (much cleaner,
likely); but then I'd need to evaluate a template block in my function
(because I don't want to have all the HTML hardcoded, obviously); how do I do
this?
I'd imagine the call would look something like this:
[% BuildNav(...) BLOCK %]
... nav template
[% END %]
An even _further_ option would be to have the Perl function return a specially
formatted data structure which I could traverse with a FOREACH loop and where
each step contained information of whether to go up a level (ie, close a
</UL>) or go down one further (start a new <UL>).
Any thoughts on this?
Oh, and while I'm at it, I saw a recent discussion on Image modules; does
anyone have a nice module for generating image galleries etc?
Sincerely,
Lars
--
Principal Squirrel
SuSE Labs - Research & Development, SuSE Linux AG
"If anything can go wrong, it will." "Chance favors the prepared (mind)."
-- Capt. Edward A. Murphy -- Louis Pasteur