You are here: Re: [SMARTY] Indexed Arrays in Config Files « Smarty Templates Posts « IT news, forums, messages
Re: [SMARTY] Indexed Arrays in Config Files

Posted by Monte Ohrt on 09/08/05 17:02

This sample works for me. Be sure config_overwrite gets set to false,
the behavior you are seeing is when it is true. I assume you have
{config_load} in the template...

Todd wrote:

>Thanks.
>
>I am doing this in my code:
>$smarty->config_overwrite = false;
>$smarty->display('page.tpl');
>
>This in my config:
>stylesheets = "styles/_common.css"
>stylesheets = "styles/_common_interior.css"
>stylesheets = "styles/main_nav_interior.css"
>stylesheets = "styles/left_nav.css"
>
>And then this in my template:
>{foreach from=#stylesheets# item=stylesheet_loc}
> <link href="{$stylesheet_loc}" rel="stylesheet" type="text/css"
>media="screen" />
>{/foreach}
>
>And I am only getting one of the four values I set in the config:
><link href="styles/left_nav.css" rel="stylesheet" type="text/css"
>media="screen" />
>
>Thanks,
>Todd
>
>--- boots <jayboots@yahoo.com> wrote:
>
>
>
>>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/
>>
>>
>>
>
>
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация