Re: [SMARTY] Referencing complex associative array

From: Date: Thu, 28 Apr 2005 16:37:43 +0000
Subject: Re: [SMARTY] Referencing complex associative array
References: 1 2  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-12548@lists.php.net to get a copy of this message
Abdul-Wahid Paterson wrote:
{section name=news loop=$result.ITEMS}
     ...{$result.ITEMS.[news].LINK}...
{/section}
Roger Thomas wrote: How do I reference, say, the LINK under ITEMS ? Please advise.
array(10) { ...
["ITEMS"]=> array(5) { [0]=> array(5) {
     ["TITLE"]=>
     string(31) "Early Iraq legal opinion leaked"
     ["DESCRIPTION"]=>
     string(115) "The attorney general doubted the Iraq war would be legal without a new resolution from the UN, leaked advice shows."
     ["LINK"]=>
     string(79) "http://news.bbc.co.uk/go/rss/-/1/hi/uk_politics/vote_2005/frontpage/4491105.stm"
     ["GUID"]=>
     string(70) "http://news.bbc.co.uk/1/hi/uk_politics/vote_2005/frontpage/4491105.stm"
     ["PUBDATE"]=>
     string(27) "Wed, 27 Apr 05 22:32:09 GMT"
} ...
For complex array structures I find it easier to read/write the template markup by using assign() here, especially if you're going to use multiple values from the array: <ul> {section name=news value=$result.ITEMS} {assign value=$result.ITEMS[news] var="item"} <li>
    <h3><a href="{$item.LINK}">{$item.TITLE}</a></h3>
    <p>{$item.DESCRIPTION}</p>
</li> {/section} </ul> FWIW! -- Maximillian Von Schwanekamp http://www.neptunewebworks.com/

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