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

From: Date: Mon, 23 Jul 2001 18:21:36 +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-1253@lists.php.net to get a copy of this message
Your best bet is to have Smarty parse the XML file, then run that through your xml parser. One way or another, you will need the data parsed by your xml parser and by Smarty. // assign vars to smarty here // parse xml file through smarty $xml_data = $smarty->fetch("cachecache.xml"); // parse the xml data into arrays xml_parse($xml_data); // assign your xml arrays to smarty here // display your template $smarty->display("index.tpl"); Luc Saint-Elie wrote: > > At 09:24 23/07/01 -0500, Monte Ohrt wrote: > >You will need to include the external source as a template. If there are > >no other curly braces in the XML file, should should be able to just > >include it. > > > >{include file="foo.xml"} > > > >And if this XML file is coming from a database or other resource, you > >will want to create a resource function and register it. > > > >{include file="xml:foo.xml"} > > Hello, > > I tried, this doesn't work.. and that seem rather normal. If I do that the > templates system tries to include my XML file that is absolutely not what I > want to do. > The conclusion is that I absolutely don't understand.... > > Here is the sequence : > > step 1 : a XML file (cachecache.xml) contains somes variables (for example > {$ip} ) > step 2 :a php file ( xmlprocess.php) calls this XML file and processes it > using phpxml class the result is two arrays > step 3 : the php file "assigns" the resulting arrays to the template > (display.article.tpl) > step 4 : the php file "assigns" several variables corresponding to the > variables from step 1 to the template (display.article.tpl) > step 5 : the php file "displays" the main template (index.tpl) that then > "includes" display.article.tpl > > If i set debugging to true, the assigned template variables are OK.. my > problem is that thE SEARCH/replace is done on the template > (display.article.tpl) file and not in the content of the array (the one > that contains the XML data). > > Perhaps the solution would be to do this work in the php file to search > inside the array and replace the {...} placeholder by the actual value or > to do this at processing time when parsing the XML file.... > > Luc > > --- > You are currently subscribed to smarty as: monte@ispi.net > To unsubscribe send a blank email to $subst('Email.Unsub') > Visit Smarty's homepage at http://www.phpinsider.com/php/code/Smarty/ > -- Monte Ohrt <monte@ispi.net> http://www.ispi.net/

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