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

Stephen Stewart Stephen.Stewart@designbyfront.com
Wed, 31 May 2006 14:22:28 +0100


Hello,

I've been using the examples in the badger book for navigation elements
built from an XML sitemap. In my case I've been trying to build the
navigation with an HTML list:

<ul>
  <li>apples</li>
  <li>oranges</li>
    <ul>
      <li>clementine</li>
      <li>mandarin</li>
      <li>satsuma</li>
      <li>tangerine</li>
    </ul>
</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:

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

My menu/nest:
[% IF loop.first %]
<ul>
[%- END -%]

<li [% IF loop.first %]class=3D"first"[%- END -%] [% IF loop.last &&
!loop.first %]class=3D"last"[%- END -%]><a href=3D"[% link.url %]"
[%- " class=3D\"$link.class\""
  IF link.class
-%]><span>[%- link.text -%] </span></a></li>
[% IF loop.last %]
</ul>
[%- END -%]

If anyone has been here before I'd be grateful of some help. (I don't
have the badger book to hand, but I believe the example I was working
from was about page 450, Chapter 11.)

Many thanks,

Stephen

--
FRONT
http://www.designbyfront.com