Re: HTML_Template_Xipe

From: Date: Sun, 29 Jun 2003 16:00:29 +0000
Subject: Re: HTML_Template_Xipe
References: 1 2  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-6305@lists.php.net to get a copy of this message
Wolfram Kriesing wrote:
Tommy Ipsen wrote:
Hi I have a problem nesting templates when using HTML_Template_Xipe... This is the short version of what I have: index.php: $options = array(
      'templateDir'  => 'templates',                // root-directory for storing templates
      'compileDir'   => 'tmp',                        // directory for compiled templates
      //'debug'        => 1,                            // debug level
      //'filterLevel'  => 9,                            // :TODO: filters nothing - only during debug-face!
      'forceCompile' => true,                         // :TODO: forces a recompilation of templates - only during debug-face!
      //'logLevel'     => 0,                            // :TODO: logs everything - only during debug-face!
      //'enable-Cache' => true,                         // enable caching of templates - remember administrative possibility to recompile!
      //'locale'       => '',                           // no translation of templates - therefore locale is not required!
      //'verbose'      => true,                          // :TODO: should be false on a production system!
      'autoBraces'    => false
); // stuff... $tpl = new HTML_Template_Xipe($options); $tpl->compile('index.tpl'); include($tpl->getCompiledTemplate()); index.tpl: <html>
    <body>
        // stuff...
        {%include content.tpl%}
    </body>
</html> This works fine, meaning content.tpl is also parsed as a template by Xipe. But I would really like to do something like:
        {%include $contentfile%}
Where $contentfile contains a filename depending on a parameter given by the user. The above code however is only possible like this:
         {include 'templates/filename.tpl';}
Which results in the template not being parsed by xipe and the $variables in filename.tpl appearing "as written" ie. not substituted with the value of the variable! Therefore my question is how to include (and parse) a file/template when the name of the file/template is stored in a variable!
i understand your problem. and in the way of using a variable there like this:
    {%include $contentfile%}
it is not possible with Xipe (yet) but i would suggest that you do another thing, may be its just a work around, but it worked fine (at least for me) use a standard php-include like this:
    {include $contentfile}
this will be parsed by the template engine and replaced by
     <?php include $contentfile ?>
which means that $contentfile is a valid file name of a php-file (not a template!). So that you have a little bit of extra work which is compiling the template in the $contentfile. i.e. if $contentfile is 'htdocs/contentFile.php' then you simply compile the template inside of this file and you have the same effect.
hth Thanks for your workaround - even though it seems a bit tiresome since I need to allow for dynamically creation of new templates using a cms-system - then I have to dynamically create a matching php-file for each template-file :-/
Do you have any idea if it will be a lot of work to modify Xipe to allow for this added functionality?

« previous php.pear.general (#6305) next »