I'm working on a site where a URL calls a different template depending on where it's been called from.

For instance if the script gets called at myserver.com/foo/ then the script parses the path and uses the template "foo.tmpl". If it's in myserver.com/bar/ it uses the template "bar.tmpl" and so on.

I'd like to go one further -- I'd like "foo.tmpl" to include a file: <tmpl_include name="foo.inc"> and "bar.tmpl" to include a different file <tmpl_include name="bar.inc">.

Is there any way to do this? The obvious way to do it is something like, create a variable $foonav and pass it to the template and have

<tmpl_if name="foonav"> <tmpl_include name="foo-nav.inc"> </tmpl_if>

And so on for a bunch of other variables. But that feels pretty kludgy.

And which brings me to my second question, why, when I do this:

<tmpl_if name="foonav"> <tmpl_include name="foo-nav.inc"> </tmpl_if> <tmpl_if name="barnav"> <tmpl_include name="bar-nav.inc"> </tmpl_if>
Does it cause the following error message: HTML::Template->new() : Cannot open included file /path/to/foo-nav.inc : file not found. at /usr/share/perl/5.8/HTML/Template.pm line 2241.

Even when I haven't ever called on "bar-nav.inc"? No matter whether the variable is passed to grab the include, I get the error. I'm busy developing and haven't created the file yet. It somehow seems inefficient for HTML::Template to be checking the existence of files when it doesn't need to. Can I tell it not to?



($_='kkvvttuu bbooppuuiiffss qqffssmm iibbddllffss')
=~y~b-v~a-z~s; print

In reply to Two questions about HTML::Template by Cody Pendant

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.