|
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 |
chriscolden Smarty Rookie
Joined: 21 Feb 2006 Posts: 11 Location: Birmingham, UK
|
Posted: Tue Jul 11, 2006 2:00 pm Post subject: Array Access With Section Help |
|
|
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 |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Tue Jul 11, 2006 3:32 pm Post subject: |
|
|
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 |
|
SkratchCat Smarty n00b
Joined: 21 Oct 2005 Posts: 1 Location: Seattle, WA
|
Posted: Thu Jul 20, 2006 6:09 am Post subject: This seems to work |
|
|
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 |
|
|
|
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
|