[Templates] closing a nested list correctly on the last item

Larry Leszczynski larryl@emailplus.org
Wed, 31 May 2006 07:41:00 -0600 (Mountain Daylight Time)


Hi Stephen -

> <ul>
>  <li>apples</li>
>  <li>oranges</li>
>    <ul>
>      <li>clementine</li>
>      <li>mandarin</li>
>      <li>satsuma</li>
>      <li>tangerine</li>
>    </ul>
> </ul>

I think this should probably be:

   <ul>
    <li>apples</li>
    <li>oranges
      <ul>
        <li>clementine</li>
        <li>mandarin</li>
        <li>satsuma</li>
        <li>tangerine</li>
      </ul>
    </li>
   </ul>


> However I have a problem when the last item in the outer list has sub
> items in the version I've created. If I use loop.last in menu/nest (from
> the Badger Book example) the outer <ul> will close before the inner <ul>
> is built:

Look at page 152 in the Badger book, you can create your own iterator for 
the outer loop, e.g.:

    [% USE my_iterator = iterator(my_list_for_outer_loop) %]

and then do things like:

    [% FOREACH thing IN my_iterator %]
       [% FOREACH sub_thing IN thing.sub_things %]
          [% IF loop.last %]
             ... this is for the inner loop ...
          [% END %]
          [% IF my_iterator.last %]
             ... this is for the outer loop ...
          [% END %]
       [% END %]
    [% END %]



Larry