i try to get blockMatrix value with different way(.one()
& .all()
) in the same page (this page consists of several templates) but the result is weird. Here how i do it:
i have a blockMatrix("mediaContentComponent") with 2 types:
textContentComponent
=> only plain text fieldimageContentComponent
=> only asset field
At first value, i try to get only the first textContentComponent
value in blockMatrix with entry.mediaContentComponent.type('textContentComponent').one()
, This query will run in base.twig.
then on second value, i try to get all the blockMatrix values with entry.mediaContentComponent.all()
, this query will run in content.twig.
Now after all query is running here is the weird result, the first value didn't have any problem but the second value didn't have any imageContentComponent
and only have textContentComponent
. I am curious, is this expected behaviour that Craft have?
Note:
- the blockMatrix value is added randomly by editor. And here is how i handle the second value:
{% set contents = entry.mediaContentComponent.all() %}
{% for content in contents %}
{% switch content.type %}
{% case 'imageContentComponent' %}
{% case 'textContentComponent' %}
{% endswitch %}
{% endfor %}