5

I want to limit the rows returned here to 4, then if loop.index is 3 display a separator and then output the last row.

Does the table field have that kind of control?

{% for row in registration.registrationCost %}
    <li class="circle">
        <h3 class="registration-cost">{{ row.cost }}</h3>
        <hr/>
        <h5>Through</h5>
        <h4>{{ row.date }}</h4>
    </li>          
{% endfor %}

1 Answer 1

7

According to the Craft docs , the table field returns an array of rows.

Assuming that is the case, you should be able to use the Twig slice filter:

{% for row in registration.registrationCost | slice(0, 3) %}

You can then use a simple conditional to output the row divider:

{% if loop.index == 3 %}  
    <hr>  
{% endif %}

Stephen

4
  • Thank you Stephen. Steve Abraham just suggested the same thing. I was incorrectly using .limit() before. Jul 30, 2014 at 12:38
  • 3
    STEVE ALL THE THINGS! Jul 30, 2014 at 12:43
  • tis a fine name -- even with your funny spelling :) Jul 30, 2014 at 12:45
  • Had to comment, just to complete the set. Jul 30, 2014 at 15:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.