470,855 Members | 1,317 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,855 developers. It's quick & easy.

multidimensional arrays passed to Smarty?

Does Smarty support assigning multidimensional arrays? I've tried to get
it working, but just can't get it.

can someone help me?
this is what I have in my php file:

$side_bar =
array('link' => array( 'index.php',
'estate.php',
'text' => array( 'Home',
'Real Estate')));
$smarty->assign ("side_bar", $side_bar);

then in my template file I have this:

{section name=i loop=$side_bar}
<tr><td width="19"><img src="images/td_background_left.gif" width="19"
height="22" alt="" border="0"></td>
<td align="left" valign="center" height="22" width="118"
background="images/td_background_right.gif">
<p><span style="font-family: Arial; color:black; font-size: 8pt;">
{if $side_bar.link.i neq ""}
<a href= {$side_bar.link.i} style="text-decoration:none; color:black;">
<b>& {$side_bar.text.i}</b></a></span></p></td></tr>
{else}
<a><b>&{$side_bar.text.i}</b></a></span></p></td></tr>
{/if}
{/section}

with this code, only one row is produced in the table. I guess it's
because $side_bar only has two values which have more values beneath
them. How can I create a side bar that will have the link and then text
that I store in the array? Does it work to have an Associative array
mixed with an Indexed array, and then display the indexed array the way
I tried?

Obviously it does not work like this. I'm fairly new to PHP and Smarty,
so if anyone has suggestions on how I can get this done, please tell me.

Thanks,
Mark
Jul 17 '05 #1
2 13636
In article <44******************************@news.teranews.co m>,
Mark <do***************@hotmail.com> wrote:
Does Smarty support assigning multidimensional arrays? I've tried to get
it working, but just can't get it.


Yes. I use them in {foreach} loops, like this:

{foreach from=$multi_dimensional_array item=array}
<tr><td>{$array.value1}</td><td>{$array.value2}</td></tr>
{/foreach}

JP

--
Sorry, <de*****@cauce.org> is een "spam trap".
E-mail adres is <jpk"at"akamail.com>, waarbij "at" = @.
Jul 17 '05 #2
Jan Pieter Kunst wrote:
In article <44******************************@news.teranews.co m>,
Mark <do***************@hotmail.com> wrote:

Does Smarty support assigning multidimensional arrays? I've tried to get
it working, but just can't get it.

Yes. I use them in {foreach} loops, like this:

{foreach from=$multi_dimensional_array item=array}
<tr><td>{$array.value1}</td><td>{$array.value2}</td></tr>
{/foreach}

JP


Thank you, I got it to work now.
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by shane | last post: by
2 posts views Thread by Terry | last post: by
9 posts views Thread by Charles Banas | last post: by
3 posts views Thread by Ravi Singh (UCSD) | last post: by
21 posts views Thread by utab | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.