Re: [SMARTY] Building output from an array(array(array(array())))

From: Date: Sat, 13 Nov 2004 16:39:23 +0000
Subject: Re: [SMARTY] Building output from an array(array(array(array())))
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-11959@lists.php.net to get a copy of this message
On Sat, Nov 13, 2004 at 08:06:21AM -0800, Stephen Lawrence wrote: > Hey all, I have an array of values that I want to display and I cannot > seem to get the correct template syntax/structure do do it. > > Here is the array that I am assiging to smarty. Basically it is made up > of 2 colums of a database (URL and TARGET): > ********************************* > > [_tpl_vars] => Array > ( > > [user_navlinks] => Array > ( > [0] => Array > ( > [0] => Array > ( > [0] => > http://www.yahoo.com > [1] => > http://www.google.com > ) > > ) > > [1] => Array > ( > [0] => Array > ( > [0] => _blank > [1] => _new > ) > > ) > > ************************************** > > I then want to create an href link from these values, but I cannot seem to > figure out how to pull one item from each array (one from URL, one from > TARGET_, display them, then pull values from the next rows, like this: > <a href="http://www.yahoo.com" > target="_blank">http://www.yahoo.com</a> > <a href="http://www.google.com" > target="_new">http://www.google.com</a> {foreach from=$user_navlinks[0][0] key=i item=uri} <a href="{$uri}" target="{$user_navlinks[1][0][$i]}">{$uri}</a> {/foreach} but your array seems to have some odd redundancies. if it was just: [user_navlinks] => Array ( [0] => Array ( [uri] => http://www.yahoo.com [target] => _blank ) [1] => Array ( [uri] => http://www.google.com [target] => _new ) ) the loop would be a little simpler and clearer: {foreach from=$user_navlinks item=link} <a href="{$link.uri}" target="{$link.target}">{$link.uri}</a> {/foreach} messju > ************************************** > > I have tried foreach, and section, but can't seem to display the > user_navlinks array in that fashion. > > Any ideas? > > -- > Smarty General Mailing List (http://smarty.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php

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