What are I doing wrong here?

I'm setting block types 'stripCustom' and 'stripShowroom' to 'stripBlock'

{% set stripBlock = entry.contentImage.type(['stripCustom', 'stripShowroom']) %}

Then in a loop checking if 'stripBlock' is last and the current block is last but one.

<div class="section {% if loop.last == stripBlock and loop.revindex0 == 1 %}gutter-bottom--double{% endif %}">
  • 2
    I don't think you can compare loop.last to your stripBlock variable. I think loop.last just is or isn't. May 5 '17 at 16:02
  • Oh. So is there a way to test is a certain block type is last?
    – sarah3585
    May 6 '17 at 7:21
  • Did my answer below help you with your issue? May 10 '17 at 16:44
  • Haven't had a chance to look yet as I've been pulled away from that project, I will look today.
    – sarah3585
    May 11 '17 at 9:38

To test if the current block is the last in the loop and of a certain type, you could do something like:

{% if loop.last and block.type == "yourBlockType" %}yes{% endif %}

or shorthand

{{ loop.last and block.type == "yourBlockType" ? 'yes' : 'no' }}

In the above example replace 'no' with '' to output nothing. It's just there if you want to output something in case of false

or even shorter

{{ loop.last and block.type == "yourBlockType" ? 'yes' }}

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.