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.

Conditional Number Divisible By 3

October 28, 2011 3:36pm

Subscribe [2]
  • #1 / Oct 28, 2011 3:36pm

    Certified K

    10 posts

    Hi All,

    I’m trying to list portfolio items in groups of 3.  When the total number of entries isn’t divisible by 3, then I want a dummy item to be inserted to fill out the rest.  For example…

    If 6 items…

    <ul>
    <li>Project 1</li>
    <li>Project 2</li>
    <li>Project 3</li>
    <li>Project 4</li>
    <li>Project 5</li>
    <li>Project 6</li>
    </ul>

    If 5 items…

    <ul>
    <li>Project 1</li>
    <li>Project 2</li>
    <li>Project 3</li>
    <li>Project 4</li>
    <li>Project 5</li>
    <li>Dummy Item</li>
    </ul>

    If 4 items…

    <ul>
    <li>Project 1</li>
    <li>Project 2</li>
    <li>Project 3</li>
    <li>Project 4</li>
    <li>Dummy Item</li>
    <li>Dummy Item</li>
    </ul>


    I figured I could use conditional global variables, but I don’t know how to do operators within the condition.  For example, is there a way to do “If #entries/3 and remainder is 0, then…”?  Any help would be appreciated.  Thanks.

     

  • #2 / Oct 29, 2011 9:12am

    John St-Amand

    865 posts

    No way immediately comes to mind.  Out of curiosity, why insert the dummy items?  Is it purely to control the display in 3’s?  The switch variable comes to mind as a way to control your display in blocks of 3, though it doesn’t insert dummy values afterwards, but does allow you to specify formatting at the entry level but in a pattern - 3, 4, 5 - up to you.

  • #3 / Oct 29, 2011 10:43pm

    Certified K

    10 posts

    Hi John,

    The dummy items are there for design purposes.  I may not go with it, but wanted to figure out the best way to do it if I stick with it.

    I was thinking there was some way to incorporate conditionals and switch variables too, but can’t think of anything short of explicitly saying, if 5, if 7, if 8, then…  I might end up going with that.  Thanks for the help.

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

ExpressionEngine News!

#eecms, #events, #releases