New Plugin: :nth
Booyant (they make NavEE) released a new plugin to help make dynamically generating class names easier. It’s called :nth.
:nth allows you to dynamically generate a class name at specified intervals on Expression Engine elements. Perhaps you have a list that is being dynamically populated from an EE weblog and you’d like to create a grid layout, but the last column items need to behave differently than the rest of the items. Simply wrap the whole mess in a pair of nth tags and set the class and interval parameters to your desired class name and interval.
I’ve always used some PHP in the template for situations like that (and these situations happen frequently) but this seems like a nice way for non-PHP coders to achieve the same functionality in a straight-forward way or even for PHP coders who want to limit the amount of PHP they have to write in their templates.
:nth looks to only be available for EE 1.6 at this time and it’s a free download.
Brendan Underwood — 18:22 on 07.27.2010
I’ve used the {switch} single variable for this in the past. So if I needed a class on every fourth item i’d have switch=”|||last”. It means the class attribute is rendered out each time, but it still works.
Michael C. — 02:22 on 07.28.2010
I was going to say what Brendan said; how is this all that different from using {switch}?
Wes — 09:40 on 07.28.2010
I can see where this would be helpful instead of using switch.
Imagine this code:
{exp:channel:entries limit=“2”}
{matrix}
Entry {entry_id} - {switch=”||last”}<br>
{/matrix}
{/exp:channel:entries}
So in the code above we are getting two entries with matrices. Imagine the 1st entry has two rows in the matrix. Imagine the 2nd entry has four rows. You would end up with something like this:
Entry 1 -
Entry 1 -
Entry 2 -
Entry 2 -
Entry 2 - last
Entry 2 -
Because matrix uses it’s own switching system, it’s switch is ignorant of previous entry’s matrix switch values. Thus, having a plugin to do all of this after the tagdata is rendered will help solve the problem.
This is just in theory, but I think this should work.