<p>With the below <code>{{ module.type }}</code> outputs <code>'moduleFAQ'</code> but <code>firstFAQId</code> and <code>lastFAQId</code> don't output anything. Why is that?</p>

<pre><code>{% for module in module.children.all() %}
    {% set firstFAQ = module.type('moduleFaq').one() %}
    {% set firstFAQId = firstFAQ ? firstFAQ.id : null %}
    {% set lastFAQ = module.type('moduleFaq').last() %}
    {% set lastFAQId = lastFAQ ? lastFAQ.id : null %}
    {{ module.type }} / {{ firstFAQ }} / {{ lastFAQ }}
{% endfor %}
</code></pre>

CC BY-SA 4.0
2020-05-01T12:40:59.333Z
Could you explain what you are trying to achieve a bit more? This is a loop so so you might not be able to get `lastFAQ` until the loop has finished running. I'm not familiar with Neo but if all you want are the first and last id of a certain block type, `{% set firstFAQId = module.children.type('moduleFaq').one() %}` and `{% set lastFAQId = module.children.type('moduleFaq').inReverse().one() %}` should work (not tested).
Oli
CC BY-SA 4.0
2020-05-02T04:23:15.630Z
So a block can have some plain text, followed by a series of FAQs, followed by some more text. Before and after the FAQs, there needs to be a wrapping element. I'm already looping through `module.children.all` so I don't need to have that when looking for the block type. If you take that out, what I have is essentially the same as you.
Tyssen
<plugin-neo>
Getting ID of first and last Neo blocks of certain type
# Getting ID of first and last Neo blocks of certain type

(Asked by: username_0 on 2020-04-30)

With the below {{ module.type }} outputs 'moduleFAQ' but firstFAQId and lastFAQId don't output anything. Why is that?
{% for module in module.children.all() %}
    {% set firstFAQ = module.type('moduleFaq').one() %}
    {% set firstFAQId = firstFAQ ? firstFAQ.id : null %}
    {% set lastFAQ = module.type('moduleFaq').last() %}
    {% set lastFAQId = lastFAQ ? lastFAQ.id : null %}
    {{ module.type }} / {{ firstFAQ }} / {{ lastFAQ }}
{% endfor %}

**Tags:** plugin-neo
> **Comments:**
> **username_1**: Could you explain what you are trying to achieve a bit more? This is a loop so so you might not be able to get `lastFAQ` until the loop has finished running. I'm not familiar with Neo but if all you want are the first and last id of a certain block type, `{% set firstFAQId = module.children.type('moduleFaq').one() %}` and `{% set lastFAQId = module.children.type('moduleFaq').inReverse().one() %}` should work (not tested).  
> **username_0**: So a block can have some plain text, followed by a series of FAQs, followed by some more text. Before and after the FAQs, there needs to be a wrapping element. I'm already looping through `module.children.all` so I don't need to have that when looking for the block type. If you take that out, what I have is essentially the same as you.  

---

## 0 answers

