ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

.last tag in an endless li loop

May 12, 2013 5:50pm

Subscribe [2]
  • #1 / May 12, 2013 5:50pm

    Wabi Sabi Press

    8 posts

    Hi,
    I am not sure if anyone can help. I am trying to apply a .last class to the last item in a 3 column row. However I need to keep looping the items to create more rows below, so that I have 3 column, then 3 more columns below and so on.

    I am using this code below, which works well for 3 items on a 3 column row. However this only works for the first 3 column row. Any other 3 column rows after and below do not have the .last class applied to the last item in that row.

    <ul>
    {exp:channel:entries channel="store"}
    <li class="span4 {if count == 3}last{/if}"> <!-- start .span4 -->
    <a href="http://{title_permalink=store/detail}">_{product_image_one}_<div id="overlay">_<h4>{product_manufacturer}</h4><p>_{short_description}_</div>_</a><br />
    </li><br />
    {/exp:channel:entries}<br />
    </ul>

    So what I need to do is apply the .last class to each last item in each row, like this:

    Row1: 1 2 3 (.last)
    Row2: 1 2 3 (.last)
    and so on.

    Many thanks in advance if you can help me.

    Best regards

    Graham

  • #2 / May 13, 2013 11:40am

    Kevin Cupp

    791 posts

    Hi Graham,

    Sounds like the {switch=} variable does what you need:

    http://ellislab.com/expressionengine/user-guide/modules/channel/channel_entries.html#switch

    For your example, you would need something like this:

    {switch='||last'}

    Let us know if that doesn’t work.

    Kevin

  • #3 / May 13, 2013 3:59pm

    Wabi Sabi Press

    8 posts

    Hi Kevin,

    Many thanks for your kind reply.

    Yes your answer it works. I also this article to help other folk.

    http://joviawebstudio.com/index_ee.php/blog/dynamic_class_names_with_expressionengine/

    Please find an update to my code below:

    <ul>
    {exp:channel:entries channel="store"}
    <li class="span4 {switch="||last"}"> <!-- start .span4 -->
    <a href="http://{title_permalink=store/detail}">_{product_image_one}_<div id="overlay">_<h4>{product_manufacturer}</h4><p>_{short_description}_</div>_</a><br />
    </li><br />
    {/exp:channel:entries}<br />
    </ul>

    Many thanks

    Graham

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases