[Templates] closing a nested list correctly on the last item
Stephen Stewart
Stephen.Stewart@designbyfront.com
Wed, 31 May 2006 15:27:26 +0100
Hi,
=20
Larry wrote (31/05/2006):
> I think this should probably be:
>=20
> <ul>
> <li>apples</li>
> <li>oranges
> <ul>
> <li>clementine</li>
> <li>mandarin</li>
> <li>satsuma</li>
> <li>tangerine</li>
> </ul>
> </li>
> </ul>
You're right. The O'Reilly HTML & XHTML Definitive Guide sent me down
the wrong path there.
IvorW wrote (31/05/2006):
> Can you give more of your template please. Could you include the
> FOREACH and matching END directives. The normal way of approaching
> what you want is to nest loops.
This is menu/nest,
[% DEFAULT pad =3D '';
DEFAULT level =3D 1;
FOREACH item =3D menu.items;
pad;
UNLESS notoplevel && level =3D=3D 1;
INCLUDE menu/text
link =3D {
text =3D item.name
url =3D item.url
class =3D item.hot ? 'menuselect' : 'menu'
};
END;
IF item.subs && !norecur;
INCLUDE menu/nest
level =3D level + 1
menu =3D item
pad =3D pad ? ""
: "";
END;
END
-%]
which uses menu/text,
[% 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 -%]
Maybe I shouldn't be using this example at all to do this?
Stephen
--
FRONT
http://www.designbyfront.com