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

<pre><code>{% if loop.last and block.type == "yourBlockType" %}yes{% endif %}
</code></pre>

<p>or shorthand</p>

<pre><code>{{ loop.last and block.type == "yourBlockType" ? 'yes' : 'no' }}
</code></pre>

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

<p>or even shorter</p>

<pre><code>{{ loop.last and block.type == "yourBlockType" ? 'yes' }}
</code></pre>

CC BY-SA 3.0
2017-05-06T14:31:52.033Z
2017-05-06T15:17:03.793Z
2017-05-06T15:17:03.793Z
AbbeyDesign
<p>What are I doing wrong here?</p>

<p>I'm setting block types 'stripCustom' and 'stripShowroom' to 'stripBlock'</p>

<pre><code>{% set stripBlock = entry.contentImage.type(['stripCustom', 'stripShowroom']) %}
</code></pre>

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

<pre><code>&lt;div class="section {% if loop.last == stripBlock and loop.revindex0 == 1 %}gutter-bottom--double{% endif %}"&gt;
....
&lt;/div&gt;
</code></pre>

CC BY-SA 3.0
2017-05-05T16:02:28.070Z
I don't think you can compare loop.last to your stripBlock variable. I think loop.last just is or isn't.
AbbeyDesign
CC BY-SA 3.0
2017-05-06T07:21:56.457Z
Oh. So is there a way to test is a certain block type is last?
sarah3585
CC BY-SA 3.0
2017-05-10T16:44:49.510Z
Did my answer below help you with your issue?
AbbeyDesign
CC BY-SA 3.0
2017-05-11T09:38:49.177Z
Haven't had a chance to look yet as I've been pulled away from that project, I will look today.
sarah3585
<matrix><loop><block-types>
loop.last of a certain block type
# loop.last of a certain block type

(Asked by: username_0 on 2017-05-05)

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.

....

**Tags:** matrix, loop, block-types

> **Comments:**
> **username_1**: I don't think you can compare loop.last to your stripBlock variable. I think loop.last just is or isn't.  
> **username_0**: Oh. So is there a way to test is a certain block type is last?  
> **username_1**: Did my answer below help you with your issue?  
> **username_0**: Haven't had a chance to look yet as I've been pulled away from that project, I will look today.  

---

## 1 answers

### Answer by username_1 on 2017-05-06. Score: 2

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' }}


---

