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.

Fill in a 2column Table

February 17, 2012 4:27pm

Subscribe [2]
  • #1 / Feb 17, 2012 4:27pm

    Kaspar

    30 posts

    Hi

    I have a question for proper coding.

    I want to fill in a 2 columns Table with a channel entry.

    So I wrote something like this:

    <table>
    <tbody>  
     <tr>
          {exp:channel:entries channel="kunden" orderby=”entry_date”}
               <td><a href="http://{link}class=kunden">{title}</a></td>
          {/exp:channel:entries}
     </tr>    
    </tbody>
    </table>

    But this fills in just more and more columns so the whole table ends up with 10 columns and one row.

    Now my question is how to write this in a proper way so there are just 2 columns and everything lines up in rows.

    My only Idea was to populate the td tag and ad offset to the exp:entry but that looks quite silly to me:

    <table>
          <tbody>  
           <tr>
            {exp:channel:entries channel="kunden" orderby=”entry_date” limit="2"}
             <td><a href="http://{link}class=kunden">{title}</a></td>
            {/exp:channel:entries}
           </tr>
           <tr>
            {exp:channel:entries channel="kunden" orderby=”entry_date” limit="2" offset="4"}
             <td><a href="http://{link}class=kunden">{title}</a></td>
            {/exp:channel:entries}
           </tr>
           <tr>
            {exp:channel:entries channel="kunden" orderby=”entry_date” limit="2" offset="6"}
             <td><a href="http://{link}class=kunden">{title}</a></td>
            {/exp:channel:entries}
           </tr> 
           <tr>
            {exp:channel:entries channel="kunden" orderby=”entry_date” limit="2" offset="8"}
             <td><a href="http://{link}class=kunden">{title}</a></td>
            {/exp:channel:entries}
           </tr>
           <tr>
            {exp:channel:entries channel="kunden" orderby=”entry_date” limit="2" offset="10"}
             <td><a href="http://{link}class=kunden">{title}</a></td>
            {/exp:channel:entries}
           </tr>
           <tr>
            {exp:channel:entries channel="kunden" orderby=”entry_date” limit="2" offset="12"}
             <td><a href="http://{link}class=kunden">{title}</a></td>
            {/exp:channel:entries}
           </tr>      
          </tbody>

    Is there a better way?

    thank you

  • #2 / Feb 17, 2012 4:44pm

    Boyink!

    5011 posts

    I’d look either at conditionals and the count/total results variables or possibly a clever use of the switch variable.

  • #3 / Feb 18, 2012 5:55am

    Kaspar

    30 posts

    YES. It works well with a switch tag.
    The code looks like this now:

    <table>
     <tbody>
      {exp:channel:entries channel="kunden"}
       {switch='<tr>|'}<td><a href="http://{link}class=kunden">{title}</a></td>{switch='|</tr>'} 
      {/exp:channel:entries}
     </tbody>
    </table>

    Felling like a badass hacker right now 😉

    Theank you for this great hint.

  • #4 / Feb 18, 2012 6:22am

    Boyink!

    5011 posts

    Cool deal!

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

ExpressionEngine News!

#eecms, #events, #releases