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

Array Access With Section Help

 
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
chriscolden
Smarty Rookie


Joined: 21 Feb 2006
Posts: 11
Location: Birmingham, UK

PostPosted: Tue Jul 11, 2006 2:00 pm    Post subject: Array Access With Section Help Reply with quote

Hi,

I have the follow array structure as generated by my PHP script.

Code:

{$group}   Array (6)
0 => Array (3)
  name => Web Servers
  ports => Array (2)
    0 => Array (2)
      name => HTTP
      port => 80
    1 => Array (2)
      name => HTTPS
      port => 443
  servers => Array (1)
    0 => Array (3)
      hostname => chriscolden.net
      ip => 67.18.159.90
      stats => <td align="center"><img src="images/s...
1 => Array (3)
  name => FTP Servers
  ports => Array (1)
    0 => Array (2)
      name => FTP
      port => 21
  servers => Array (1)
    0 => Array (3)
      hostname => ftp.chriscolden.net
      ip => 67.18.159.90
      stats => <td align="center"><img src="images/s...


I am using a template to output the data is a readable format. However I cannot get the tpl to load. I have narrowed it down to a bug with the way I am accessing the array (although no error is actually given).

Below is a sample of the code i am using, with nested sections.

Code:

{section name=i loop=$group}
   {$group[i]["name"]}

   {section name=ii loop=$group[i]["ports"]}
      {$group[i]["ports"][ii]["name"]}
   {/section}
{/section}


Could someone please point me in the correct direction with this problem.

Thanks very much in advance.

Chris
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Tue Jul 11, 2006 3:32 pm    Post subject: Reply with quote

I dunno but I suggest you retry using {foreach}, something like:

Code:
{foreach from=$group item=item}
    {$item.name}
    {foreach from=$item.ports item=port}
       {$port.name}
    {/foreach}
{/foreach}
Back to top
View user's profile Send private message
SkratchCat
Smarty n00b


Joined: 21 Oct 2005
Posts: 1
Location: Seattle, WA

PostPosted: Thu Jul 20, 2006 6:09 am    Post subject: This seems to work Reply with quote

I recently had a similar problem. I played around a little with the syntax and I got my content to display. Here's your code changed to reflect what I've found to work:
Code:

{section name=i loop=$group}
   {$group[i]["name"]}

   {section name=ii loop=$group[i].ports}
      {$group[i].ports[ii].name}
   {/section}
{/section}
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