Re: [SMARTY] Indexed Arrays in Config Files

From: Date: Thu, 08 Sep 2005 00:53:24 +0000
Subject: Re: [SMARTY] Indexed Arrays in Config Files
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-13009@lists.php.net to get a copy of this message
Actually, Smarty does allow for such a thing. http://smarty.php.net/manual/en/variable.config.overwrite.php Once they are setup, you can also access the array via the $smarty reserved variable {$smarty.config.foo} HTH --- Todd <thsiegel@yahoo.com> wrote: > Fair enough. I am new to Smarty and playing around a bit, but also > trying to > get something done. > > Each page in my site has one or more stylesheets depending on where > in the site > it is and what design elements it contains. I want to be able to > dynamically > add each stylesheet as necessary. So I was imagining template code > like this > (assuming arrays worked from config files): > > {foreach from=#stylesheets# item=stylesheet_loc} > <link href="{$stylesheet_loc}" rel="stylesheet" > type="text/css" > media="screen" /> > {/foreach} > > How could I implement that without assigning the array > ($smarty->assign('stylesheets', array("css1.css", > "css2.css"))) to in > my php > code? > > Thanks, > Todd > > --- Howard Katz <hkatz93@yahoo.com> wrote: > > > Todd, > > > > Typically, it is better to let us know what you want to DO with > > Smarty rather than possibly force an inappropriate method on the > > solution. > > > > So without further insight to what you are trying to do, I will > > attempt to answer your question. > > > > I do not think that Smarty allows for arrays in configuration > files. > > Smarty templates are PHP aware and you can stuff arrays into them, > > however. So, you could have the array in PHP and just feed it into > > the template. > > > > <?php > > > > require('Smarty.class.php'); > > > > $employee_id_ary[1525]='Susan Schwartz'; > > $employee_id_ary[1343]='Ashish Khadalanwal'; > > $employee_id_ary[2452]='Joe Smith'; > > > > $smarty = new Smarty(); > > $smarty->assign('employee_id_ary', $employee_id_ary); > > $smarty->assign('id', 1525); > > $smarty->display('employee_tpl.html'); > > > > > > ?> > > > > template file named employee_tpl.html: > > > > {*this is the Smarty Template*} > > Employee name = {$employee_id_ary[$id]} > > > > Output: > > Employee name = Susan Schwartz > > > > > > > > > > So, does that allow you enough flexability? > > > > -Howard > > --- Todd <thsiegel@yahoo.com> wrote: > > > > > Are numerically indexed arrays supported in config files? If > not, > > > what is a > > > good alternative? > > > > > > Thanks, > > > Todd > > > > > > -- > > > Smarty General Mailing List (http://smarty.php.net/) > > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > > > > > > > > > > > > > > > ______________________________________________________ > > Click here to donate to the Hurricane Katrina relief effort. > > http://store.yahoo.com/redcross-donate3/ > > > > -- > Smarty General Mailing List (http://smarty.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > ______________________________________________________ Click here to donate to the Hurricane Katrina relief effort. http://store.yahoo.com/redcross-donate3/

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