[Templates] Comparing foo.first
Garrett, Philip (MAN-Corporate)
Philip.Garrett@manheim.com
Thu, 17 Aug 2006 09:22:40 -0400
Bill Moseley wrote:
> Must be time to quit for the day as this doesn't make sense, and I'm
> sure it's very obvious.
>=20
> I have template code that generates <th> elements based on a passed
> in array. I set class tag on the <th> to indicate if it's a first,
> middle or last column.
>=20
> So, something like:
>=20
> FOR column =3D headers;
>=20
> col_pos =3D column =3D=3D headers.first
> ? 'first'
> : column =3D=3D headers.last
> ? 'last'
> : 'middle';
>=20
> "<th class=3D'$col_pos'>";
>=20
> [...]
>=20
> which has been working find. A added a new page today and noticed
> that the first column was <th class=3D'middle'>.
Maybe you'd be better served by the "loop" variable? It doesn't depend
on the value in the array, only its position -- which can be useful when
otherwise you'd be comparing references. Sorry, I know it doesn't tell
you what's wrong, but it works...
[% FOREACH column =3D headers %]
<th class=3D"[% loop.first ? "first" : loop.last ? "last" : "middle"
%]">
...
Philip