|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
uschleth Smarty n00b
Joined: 17 Sep 2004 Posts: 2
|
Posted: Sat Sep 05, 2020 5:29 pm Post subject: how is the concept for subarrays and why |
|
|
hi.
i have the following array:
Code: | Array (2)
data => Array (3)
$key => "admin"
action => "admin"
kitas => Array (5)
0 => Array (2)
id => "5"
Name => "kita 1"
1 => Array (2)
id => "4"
Name => "kita 2"
|
this mixed multidimensional array is already assigned to the smarty template-variable $process. now, in a template i want to display just the subarray 'kitas'. but when i try
{section name=item loop=$process.kitas}
id: $process.kitas[item].id Name: $process.kitas[item].Name
{/section}
nothing happens. of course i don't want to re-assign the subarray to an own template variable because that would be redundant. i also tried some other things but nothing worked. why is that? is that a problem by design? and if, why? and how could i solve it?
regards. |
|
Back to top |
|
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
Posted: Sun Sep 06, 2020 6:37 pm Post subject: |
|
|
Correct me if I am wrong, but I see the given array in the top-most level having a two-element sub-array: 'data', and something else not shown.
Then 'data' contains a three-element array: whatever $key happens to be, 'action;, and 'kitas'.
Then 'kitas' contains a five-element indexed array - of which only two are shown.
I think $process.kitas does not exist, but instead $process.data.kitas does exist.
Also, should something get printed, it will not be the values because there are no braces surrounding the Smarty variables. |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Tue Sep 08, 2020 4:07 pm Post subject: |
|
|
Code: | {foreach $process.data.kitas as $item}
id: {$item.id} Name: {$item.Name}
{/foreach} |
|
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|