Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

how is the concept for subarrays and why

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
uschleth
Smarty n00b


Joined: 17 Sep 2004
Posts: 2

PostPosted: Sat Sep 05, 2020 5:29 pm    Post subject: how is the concept for subarrays and why Reply with quote

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
View user's profile Send private message
bsmither
Smarty Elite


Joined: 20 Dec 2011
Posts: 322
Location: West Coast

PostPosted: Sun Sep 06, 2020 6:37 pm    Post subject: Reply with quote

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
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Tue Sep 08, 2020 4:07 pm    Post subject: Reply with quote

Code:
{foreach $process.data.kitas as $item}
id: {$item.id} Name: {$item.Name}
{/foreach}
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP