3

I want to apologize if I'm not asking the question correctly, but basically this is what I want to do:

I have this craft.entries:

{% paginate craft.entries.section('example').limit(10) as entriesOnPage %}
  {% for entry in entriesOnPage %}
    <li class="class-A">{{ entry.title }}</li>
  {% endfor %}
{% endpaginate %}

How do I insert another list-item with a different class that has to always stay in same position. For this example in the 3rd spot, to look something like this:

<li class="class-A">I'm a title</li>
<li class="class-A">I'm a title</li>
<li class="class-B">I'm am different</li>
<li class="class-A">I'm a title</li>
....

Once again, I apologize if I'm not using the right terms, but hopefully the code can explain it.

Thanks!

3

There's a special loop variable available in for loops which provides info about the iteration. In your case you'd just insert that list item after the 2nd iteration:

{% for entry in entriesOnPage %}
    <li class="class-A">{{ entry.title }}</li>

    {% if loop.index == 2 %}
        <li class="class-B">I'm am different</li>
    {% endif %}
{% endfor %}

If you want to do this only on select pagination pages, you'd additionally compare against the paginate variable available in between paginate tags:

{% if loop.index == 2 and paginate.currentPage == 12 %}
| improve this answer | |
  • This was perfect! Thanks for the quick and easy answer. – Ricardo Henriquez May 14 '15 at 17:27
1

You could add a new entry type to your "example" section with a single field of type entries field and use that to "pull in" your special entry into your section.

Within your entries loop you can check for the entry's entry type to switch classes:

{% set class = entry.type == 'special' ? 'class-B' : 'class-A' %}

or to include different template partials:

{% include '_partials/example_index/' ~ entry.type %}
| improve this answer | |

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.