|
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 |
edwin Smarty n00b
Joined: 22 Jul 2003 Posts: 2
|
Posted: Tue Jul 22, 2003 12:28 pm Post subject: Nested sections and associative arrays can't be combined |
|
|
Sections can be nested and sections can use associative arrays, but it is not possible to nest a section in which the outer section uses an associative array.
Example nested section, which doesn't work:
(I want to use $clientArray[client].clientnr as the index for the inner section)
Code: |
{section name=client loop=$clientArray}
Clientname: {$clientArray[client].clientname}<br>
Clientnumber: {$clientArray[client].clientnr}<br>
Orders:<br>
{section name=order loop=$orderArray[$clientArray[client].clientnr]}
$orderArray[$clientArray[client].clientnr][order].ordernr<br>
{/section}
{/section}
|
I tried all kinds of variations, to no avail.
The only solution is to make another array in PHP and use that as the outer section, but that:
1) is clumsy
2) breaks the coder-designer independancy
I suggest improving the loop attribute. |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Tue Jul 22, 2003 1:11 pm Post subject: |
|
|
maybe sth. like this:
Code: |
{section name=client loop=$clientArray}
Clientname: {$clientArray[client].clientname}<br>
Clientnumber: {$clientArray[client].clientnr}<br>
Orders:<br>
{assign var=clientnr value=$clientArray[client].clientnr}
{section name=order loop=$orderArray.$clientnr}
{$orderArray.$clientnr[order].ordernr}<br>
{/section}
{/section}
|
works for you. |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Tue Jul 22, 2003 6:41 pm Post subject: |
|
|
I find that Smarty's decoding of keys (especially via [] ) is not suitable for complicated expressions. Perhaps for a good reason; expressions like:
Code: | $orderArray[$clientArray[client].clientnr][order].ordernr |
aren't as, let us say, transparent, as one would hope to see in a template.
You should probably consider using foreach as the outer loop since foreach can explicity handle associative arrays and furthermore, provides handy user named variables for loop iterations. |
|
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
|