On Tue, 4 Jan 2005, Mark Fuller wrote:
> I just had a need to conditionally include one of a few templates dependnig
> on the value of a TMPL_VAR. One of the includes (which would not have been
> loaded) did not exist, but H::T died because it couldn't locate that file. I
> realized H::T probably loads everything at compile time and applies the
> conditions at the time the output method is called.
And just to explain why this was done in the first place,
HTML::Template allows includes to be syntactically invalid. For
example, this is valid:
<tmpl_loop foo>
<tmpl_var bar>
<tmpl_include foo_end.tmpl>
And foo_end.tmpl:
</tmpl_loop>
Obviously there's no way to parse this without doing the include at
compile-time.
Now, maybe this was a mistake. I've considered breaking this support
in my fantasy version 3 rewrite. But at least for v2 it has to stay.
> However, I still feel like I have a need to conditionally load included
> templates and I know which ones they are at compile time. It's not going to
> change over repeated outputs called on the same cached template. I'm faced
> with either structuring the template includes differently (making it uglier
> and some duplicated HTML). Or, let it load all the stuff I know I don't need
> at compile time and use a TMPL_VAR (the same value for the life of the
> template) to tell the output method which included fragment to output.
I've thought about allowing something like:
$t = HTML::Template->new(filename => 'foo.tmpl',
includes => { bar => 'bar.tmpl' });
And in foo.tmpl:
<tmpl_include name="bar">
This would have to be factored into the cache-signature, but since
that's now centralized in a single place in the code that should be
easy enough.
Actually, it occurs to me that this would be pretty easy to do with
filter in a sub-class. So you don't even have to wait for me!
> Question: Does this lead to the idea that it would be useful to have
> variables used only at compile time? When I tell it to load a
> template, why can't I give it variable name=value pairs to apply
> *only* at compile time?
Aside from doing variable includes, is there any other reason to want
this? I doubt it would be much more efficient in the general case
for just a few variables. Compared to the difficulty of coding it in
the current code-base it doesn't seem worthwhile.
-sam
-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues
Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek.
It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
_______________________________________________
Html-template-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/html-template-users