Hi all,
Using the debug in a smarty template I see this:
{$categories} Array (2)
0 => Array (3)
category_id => "4"
category_name => "cinema"
category_order => "50"
1 => Array (3)
category_id => "8"
category_name => "visiting theatre"
category_order => "50"
I need to be able to list each category like this:
cinema, visiting theatre
This is my code:
{foreach from=$categories.0 item='catkey' key ='catval'}
{if $catval=='category_name'}
{$catkey}
{/if}
{/foreach}
I've got this working but it's only look at element 0 and so I only see one category. I've tried nesting the foreach loops but I cannot get the syntax correct.
Would anyone be able to offer some guidance, I think I'm close!?
Sarah
smarty and arrays(assoc): I can't get this right...
Re: smarty and arrays(assoc): I can't get this right...
... from=$categories.0 is one array only (category_name => "cinema")sarah_h wrote: I've got this working but it's only look at element 0 and so I only see one category. I've tried nesting the foreach loops but I cannot get the syntax correct.
Would anyone be able to offer some guidance, I think I'm close!?
If you want display category names:
Code: Select all
{foreach from=$categories item='item' key ='key'}
{$item.category_name}<br />
{/foreach}
Re: smarty and arrays(assoc): I can't get this right...
I see! That did the trick. I'm learing this smarty stuff but I admit it does confuse me sometimes!
Thanks AGAIN for help Alby I appriciate it.
Sarah
Thanks AGAIN for help Alby I appriciate it.
Sarah