substituting filename in <TMPL_INCLUDE> ?

2000-04-21
2002-05-01
  • Brad Hilton

    Brad Hilton - 2000-04-21

    Hello,

    First, a big thanks for the work that has gone into this code.  It is going to be a *big* win on speed for us.

    I am very new to using HTML::Template and so I'm not sure if the following is allowed: (it's not working for me)

    <TMPL_INCLUDE name=<TMPL_VAR name=TEMPLATE>>

    This would be helpful as I often use a base template which sucks in other templates that my perl code specifies.  So, rather than hardcoding the included filename it'd be great to substitute the filename _before_ including the inner template.

    I've worked around the need a different way, but it would be cleaner if the above were allowed.

    Thanks for any tips you can offer,

    -Brad

     
    • Sam Tregar

      Sam Tregar - 2000-04-21

      That won't work for the simple reason that all <TMPL_*> tags are processed in a single pass.

      In some cases you can do a simulated variable-INCLUDE using a TMPL_VAR and a second $template object.  I've thought about adding a new() option that specifies a list of filenames and matching constants that can be used in <TMPL_INCLUDE>.  Something like:

         my $template = HTML::Template->new(filename => 'foo.tmpl', includes => {bar => 'bar.tmpl'});

      Then in the template you could say:

          <TMPL_INCLUDE NAME=BAR>

      And 'bar.tmpl' would be included.  This has subtle implications for the caching mechanisms which assume immutable includes...  It could be hard to implement right. 

      If you're interested in discussing this feature, join the list.  Send a blank message to htmltmpl-subscribe@lists.vm.com.   As much as I like Sourceforge, this forum software is terrible.

      -sam

       
      • Matt Lopresti

        Matt Lopresti - 2002-05-01

        I've tried to do the same and even went a step further example:
        my $templateHeader = "<TMPL_INCLUDE NAME=\&quot;someHash\&quot;>";
        $template->param(INCLUDE_HEADER => $templateHeader);

        then in tmpl
        <TMPL_VAR NAME="$templateHeader">

        prints out properly and I'm not getting the <TMPL_*> error. But it isn't including it. Any ideas or fixes.

        Thanks in advance.
        Matt

         
    • Matt Lopresti

      Matt Lopresti - 2002-05-01

      I've tried to do the same and even went a step further example:
      my $templateHeader = "<TMPL_INCLUDE NAME=\&quot;someHash\&quot;>";
      $template->param(INCLUDE_HEADER => $templateHeader);

      then in tmpl

      ERROR IN POST
      <TMPL_VAR NAME="$templateHeader">

      I MEANT
      <TMPL_VAR NAME="INCLUDE_HEADER">

      prints out properly and I'm not getting the <TMPL_*> error. But it isn't including it. Any ideas or fixes.

      Thanks in advance.
      Matt

       

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks