smarty and arrays(assoc): I can't get this right...
Posted: Thu Mar 27, 2008 9:21 am
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
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