logo       

Re: RFC: Conditional TMPL_INCLUDE: msg#00008

Subject: Re: RFC: Conditional TMPL_INCLUDE
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


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
audio.irate.dev...    yellowdog.gener...    ietf.ips/2002-0...    xfree86.fonts/2...    busybox/2003-07...    emacs.jdee/2004...    linux.mandrake....    hardware.microc...    user-groups.lin...    science.analysi...    version-control...    db.filemaker.de...    cluster.openmos...    mail.eyebrowse....    text.xml.xerces...    kde.devel.kwrit...    finance.moneyda...    gcc.regression/...    network.routing...    os.freebsd.deve...    recreation.radi...    qnx.openqnx.dev...    python.xml/2002...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe