multidimensional arrays passed to Smarty?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mark

    multidimensional arrays passed to Smarty?

    Does Smarty support assigning multidimensiona l 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_l eft.gif" width="19"
    height="22" alt="" border="0"></td>
    <td align="left" valign="center" height="22" width="118"
    background="ima ges/td_background_r ight.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_b ar.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
  • Jan Pieter Kunst

    #2
    Re: multidimensiona l arrays passed to Smarty?

    In article <4425cd5bf6df55 30aa09a3b7dd476 8ac@news.terane ws.com>,
    Mark <dontmarkduecks pam@hotmail.com > wrote:
    [color=blue]
    > Does Smarty support assigning multidimensiona l arrays? I've tried to get
    > it working, but just can't get it.[/color]

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

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

    JP

    --
    Sorry, <devnull@cauce. org> is een "spam trap".
    E-mail adres is <jpk"at"akamail .com>, waarbij "at" = @.

    Comment

    • Mark

      #3
      Re: multidimensiona l arrays passed to Smarty?

      Jan Pieter Kunst wrote:[color=blue]
      > In article <4425cd5bf6df55 30aa09a3b7dd476 8ac@news.terane ws.com>,
      > Mark <dontmarkduecks pam@hotmail.com > wrote:
      >
      >[color=green]
      >>Does Smarty support assigning multidimensiona l arrays? I've tried to get
      >>it working, but just can't get it.[/color]
      >
      >
      > Yes. I use them in {foreach} loops, like this:
      >
      > {foreach from=$multi_dim ensional_array item=array}
      > <tr><td>{$array .value1}</td><td>{$array. value2}</td></tr>
      > {/foreach}
      >
      > JP
      >[/color]

      Thank you, I got it to work now.

      Comment

      Working...