Re: [SMARTY] problems with nested sections
| From: | Mike Benoit | Date: | Thu, 11 Jul 2002 15:22:57 +0000 |
| Subject: | Re: [SMARTY] problems with nested sections | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-5251@lists.php.net to get a copy of this message | ||
I posted the exact same problem to the list about 3 hours before you
did. ;)
It seems we were both trying to do the same thing, unfortunately I still
don't know how to do it, and would really appreciate finding out as I
think it would be very helpful. I wonder if Monte or Andrei could add
another example to the Smarty docs explaining it?
However, a work around, (or the way Smarty expects you to do it) is to
basically nest your arrays in to one large array, instead of splitting
them up.
Something along the lines of:
$ID_SETS array:
array(13) {
[0]=>
array(4) {
["set"]=>
int(10)
["setname"]=>
string(7) "Set Name 1"
["photos"]=>
array(7) {
[0]=>
array(3) {
["photos_client"]=>
int(10)
["photos_pub_date"]=>
string(7) "01-Jul-02"
}
[1]=>
array(3) {
["photos_client"]=>
int(30)
["photos_pub_date"]=>
string(20) "02-Jul-02"
}
[1]=>
array(4) {
["set"]=>
int(11)
["setname"]=>
string(7) "Set Name 2"
["photos"]=>
array(7) {
[0]=>
array(3) {
["photos_client"]=>
int(11)
["photos_pub_date"]=>
string(7) "01-Jul-02"
}
[1]=>
array(3) {
["photos_client"]=>
int(31)
["photos_pub_date"]=>
string(20) "02-Jul-02"
}
Once you have the array built more to suit Smarty, it should be fairly
simple to figure out the Smarty syntax as per example 7-18 located at:
http://www.phpinsider.com/php/code/Smarty/docs/language.function.section.html
Here's the basic idea. (untested and probably has several errors of
course)
{section name=set loop=$ID_SETS}
<tr><td>
{section name=photo loop=$ID_SETS[set].photos}
<table><tr>
<td nowrap>{$ID_SETS[set].photos[photo].photos_client}</td>
<td nowrap>{$ID_SETS[set].photos[photo].photos_pub_date}</td>
</tr></table>
{/section}
</td></tr>
{/section}
On Wed, 2002-07-10 at 12:16, Joeri van Oostveen wrote:
> Want I want I'll try to explain:
> I have a n number of sets, each set contains a n number of photos.
> I want to display the photos and group then with each set.
>
> I have the following (stripped) code
> {section name=set loop=$ID_SETS}
> <tr><td>
> {section name=photo loop=$PHOTOS_ID[$ID_SETS[set]]}
> <table><tr>
> <td nowrap>{$PHOTOS_TITLE[$ID_SETS[set]][photo]}</td>
> <td nowrap>{$PHOTOS_CLIENT[$ID_SETS[set]][photo]}</td>
> <td nowrap>{$PHOTOS_PUB_DATE[$ID_SETS[set]][photo]}</td>
> <td nowrap>{$SETNAME_SETS[set]}</td>
> </tr></table>
> {/section}
> </td></tr>
> {/section}
> but I get the following error(s) - one of them is enough to explain :):
> unknown tag - '$PHOTOS_TITLE[$ID_SETS[set]][photo]'
>
> I need the value from $ID_SETS[set] to get the correct photos to display
> (the photos are linked with the set through its id)
> the information is stored like this: $PHOTOS_TITLE[2]. When I replace
> the $ID_SETS[set] between the [ ] with a hard '2' then it works, but it
> has to be dynamic.
> So how can I get the value of a variable in a section to use it for an
> other variable to create a section?
>
> I hope I made the problem a little bit clear, and hopefully you have a
> solutions (or alternate way) because after a day getting errors I'm
> getting very tired of it..
>
> thanks
>
>
> --
> Smarty General Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>