Blue Eyed Devil wrote:
[SNIP]
> What I have in mind is something like...
> Today's date is [% DATE %]
>
> Normally I would have to say
>
> $template->process($template, { DATE => $obj->date() }, ...);
>
> For it to say Today's date is 06/30/2008.
>
> What I want to be able to do is:
>
> $template->process($template, {}, ...);
>
> As you can notice, process() gets no $vars passed, so it has no clue
> what tags to look for.
> From inside the process() I would call:
>
> @all_tags = $template->tags();
>
> Inside process() (by way of override) I could then have a hook that
> does something like this (expanded code for clarity - no error
> handling/checking):
>
> foreach $tag (@all_tags)
> {
> $tagObject = new $tag;
> $output .= $tagObject->run();
> }
>
> return $output;
>
> Heck, if I really want to be greedy, I'd even ask for the processing
> code to be a parameter that you could be passed so we could specify
> custom code for tags so we wouldn't even have to override anything.
>
> I might be the only person who'd like it. Tho my example is simple,
> there could be potentially many other uses for it (as with anything else).
I guess I just don't understand why you can't use the vars hash here. Are you
worried about polluting the stash with a ton of variables? If so, why not just
pass a single item in the vars hash? Something like:
my $vars = {
api => {
DATE => sub{
return $obj->date();
},
# add more as necessary.
}
};
$template->process($template, $vars, ...);
Then just use something like [% api.DATE %]
That allows you to pass parameters as well.
-- Josh
_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates