Re: passing an array to an included template

From: Date: Thu, 02 May 2002 12:15:54 +0000
Subject: Re: passing an array to an included template
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-3979@lists.php.net to get a copy of this message
"Jens Lehmann" <newsgroup@developerforum.net> schrieb im Newsbeitrag news:20020429141156.36868.qmail@pb1.pair.com... > I want to do something like the following statement: > > {include file="foo.tpl" some_array = array('foo1','foo2') } > > It doesn't work to pass an array to the included template > this way because the compiled template will loke like: > > $this->_smarty_include("foo.tpl", array( 'some_array' => > "array('foo1','foo2')" ) ); > > Is there an other possibilty for achieving this? I can't > declare the array in my PHP-Code. > > By the way: How can I see which variables are known > in an included template? The Debug-Console imho doesn't show > this by default. > > Jens Just assign your array before displaying/fetching the template. I assume that you want to pass different contents to your included sub-templates. My old[tm] solution (simple pseudo-code): in the PHP-script for each block: $block['location'] = getLocationFromWhereEver(); $block['content'] = getContentFromWhereEver(); $block['title'] = getContentFromWhereEver(); $assignedBlocks[$block['location']][]=$block; then assign the container to smarty: $smarty-> assign ('assignedBlocks', &$assignedBlocks); in your Template (this example for location 'left') then just use a section: {section name=block loop=$assignedBlocks.left} {include file="yourTemplate.tpl" content=$assignedBlocks.left[block].content title=$assignedBlocks.left[block].title} {/section} That's it.... Norbert

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