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.

{switch} for every two rows

October 23, 2013 3:28pm

Subscribe [2]
  • #1 / Oct 23, 2013 3:28pm

    ColdHands

    10 posts

    Hi all,

    I’m using EE’s Grid Field and looping the content within a table. I’ve divided the grid fields into two table rows on my site.  I need to have each grid entry have the same background, then alternate for every entry. I’ve only been able to get {switch} to alternate the background for every other row, but not for every two rows (which is listed in the code below).

    I’ve seen examples in the forum where people have used multiple pipe characters to achieve different results, so maybe that’s the solution… but I really don’t know and I can’t find any explanation of that in the user guide. I would appreciate any suggestions.

    Here’s my code:

    <table>
    {profiles}
    <!-- *********** top row *********** -->
     <tr class="{switch='odd|even'}">
      <td>{profiles:first_name}</td>
      <td>{profiles:last_name}</td>
      <td>{profiles:height}</td>
      <td>{profiles:position}</td>
      <td>{profiles:class}</td>
      <td>{profiles:level}</td>
      <td>{profiles:hometown}</td>
      <td>{profiles:state}</td>
      <td>{profiles:school}</td>
      <td>{profiles:phone}</td>
      <td><a href="mailto:{profiles:email}">{profiles:email}</a></td>
     </tr>
    <!-- *********** bottom row *********** -->
     <tr>
      <td colspan="11">{profiles:comments}</td>
     </tr>
    {/profiles}
    </table>

    Many thanks,
    John
    ExpressionEngine v2.7.2

  • #2 / Oct 23, 2013 6:05pm

    DigitalDoctors

    76 posts

    I think you need to do it like this:

    <tr class="{profiles:switch='odd|even'}">

    since switch by itself is referencing the channel entries loop switch.

  • #3 / Oct 23, 2013 9:40pm

    ColdHands

    10 posts

    DigitalDoctors,

    Thanks so much for taking the time to help. That did the trick. I just had to apply the same class to each of the two table rows. That way the two switches work tandem.

    Thanks again,
    John

    Here’s my revised code:

    <table>
    {profiles}
    <!-- *********** top row *********** -->
     <tr class="{profiles:switch='odd|even'}>
      <td>{profiles:first_name}</td>
      <td>{profiles:last_name}</td>
      <td>{profiles:height}</td>
      <td>{profiles:position}</td>
      <td>{profiles:class}</td>
      <td>{profiles:level}</td>
      <td>{profiles:hometown}</td>
      <td>{profiles:state}</td>
      <td>{profiles:school}</td>
      <td>{profiles:phone}</td>
      <td><a href="mailto:{profiles:email}">{profiles:email}</a></td>
     </tr>
    <!-- *********** bottom row *********** -->
     <tr class="{profiles:switch='odd|even'}>
      <td colspan="11">{profiles:comments}</td>
     </tr>
    {/profiles}
    </table>
  • #4 / Oct 23, 2013 9:43pm

    DigitalDoctors

    76 posts

    No probs, I remember getting tripped up by this myself when they first released grid 😊

  • #5 / Nov 10, 2013 3:56am

    ColdHands

    10 posts

    DigitalDoctors suggestion resolved my issue. For some reason, the “solution” button isn’t working for me to indicate.

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

ExpressionEngine News!

#eecms, #events, #releases