Re: How to use a Smarty variable outside the template file ?

From: Date: Tue, 24 Jul 2001 06:53:13 +0000
Subject: Re: How to use a Smarty variable outside the template file ?
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-1268@lists.php.net to get a copy of this message
Hi, Luc Saint-Elie wrote:
When doing : $file = 'xml_files/'.$section.'/'.$file; $xml_data = $tpl->fetch('../'.$file); $xml = new XML($xml_data); What is piped into the XML parser, the stream containing the XML file read by $xml_data = $tpl->fetch('../'.$file); or the compiled result of this "fetch" action ? In the second case, the problem is perhaps that the file is no more recognized as a regular XML one. In templates_c the compiled xml file is this way : <?php /* Smarty version 1.4.4, created on 2001-07-24 07:46:46
         compiled from ../xml_files/cachecache/cachecache.xml */ ?>
<?php echo '<?xml version="1.0" encoding="ISO-8859-1"?>'; ?> well, yeah, they would. It looks like the original file is actually
a PHP script. So what you are trying to do is: - run a php script which generates XML data containing Smarty template commands - feed it to Smarty - feed the result to an XML parser. Is that correct? Well ideally, you would do it another way ;-) If the only php code you have in there is <? echo ... ?>, just put the string directly in there.... But if your stuck doing it this way, you could : - write a smarty resource handler, say for resource "xml:" - in the handler: - load the XML script in a string - eval() that string to get the PHP executed (you probably need to
    escape the $ in Smarty template code).
- return the result to Smarty - feed the result of ->fetch("xml:$file") to your XML parser... That's if I get the exact nature of want you are trying to do ;-) Mike

« previous php.smarty.general (#1268) next »