Re: passing an array to an included template

From: Date: Thu, 02 May 2002 15:25:03 +0000
Subject: Re: passing an array to an included template
References: 1 2  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-3992@lists.php.net to get a copy of this message
What you're doing is including a template several times. I just want to include this template once. My only problem is to parse an array to this template (which in fact should be easy?). The template which needs to be included is a small navigation bar. I want to pass an array of strings e.g. array("Home","Forums","Java","Entry 2342"). To make it easier understandable I can reduce my question to assigning an array within Smarty (which is the same problem). If I do assign("test",array("foo1","foo2")) it won't work (without my change in the Smarty Source), because Smarty puts quotes around unquoted strings and array("foo1","foo2") is regarded as a string. So how can I assign an array within Smarty without this change in the source code? Hope the problem is clear now. ;-) 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 (#3992) next »