Published by Mijingo

movie icon image

EE Insider Blog

Spend your time learning and developing sites with ExpressionEngine and we'll use this blog to keep you informed of all the news related to ExpressionEngine and CodeIgniter.

» Read more in the Archives.

» Have a tip? Send us your EE news.

Learn ExpressionEngine Today

Over a series of 8 videos, watch and learn as Ryan builds an entire ExpressionEngine website from beginning to end. Get started now.

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.

Posted on Jul 27, 2010 by Ryan Irelan

Filed Under: EE Add-ons, EE Plugins

Brendan Underwood18: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}?

Wes09: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.