I want to fetch a specific block from a Matrix global then pass it through a macro which returns a response based on the block type. However, if I try to use slice
the type doesn't appear to be available to the macro. Has anyone experienced something similar?
eg if I set {% set timelineText = timeline.timeline %}
(where first timeinline
is my global and second timeline
is my Matrix field) then fetch a specific block from the Matrix: {% set period = timelineText|slice(0,1) %}
should return the first instance/block from the field. I can then pass this to my macro: {{ _self.doPeriod(period) }}
My macro is
{% macro doPeriod(content) %}
{% switch content.type %}
{% case 'quote' %}
...
{% case 'period' %}
...
{% endswitch %}
{% endmacro %}```
But this returns the following error: Key "type" for array with keys "0" does not exist
Any thoughts?
timelineText|slice(0,1)
all the Matrix blocks are returned. However, if I dotimelineText.first
only the first block is returned. Isslice
the right filter in this instance/for this use?{% set timelineIds = timeline.timeline.ids() %}
. Then{% set period = timeline.timeline.id(timelineIds[0:1]).first %}
with{{ _self.doPeriod(period) }}
However, this does mean a new DB request for each block which seems a bit excessive