By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,050 Members | 1,343 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,050 IT Pros & Developers. It's quick & easy.

multidimensional arrays passed to Smarty?

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.