- Issue created by @pdureau
Automatically closed - issue fixed for 2 weeks with no activity.
If you use Grid Row component in a view and you have only one result, you will get this fatal error:
Exception: Object of type Drupal\node\Entity\Node cannot be printed. in Drupal\Core\Template\TwigExtension->escapeFilter()
Because content is a single renderable, so we are looping on the renderable properties:
{% for item in content %}
{% set col_sizes = [fr_col, fr_col_sm, fr_col_md, fr_col_lg, fr_col_xl] %}
<div{{ create_attribute({class: col_sizes}) }}>
{{ item }}
</div>
{% endfor %}
Since Twig 3.11, there are 2 new tests: is sequence
and is mapping
, so we can use them to check if there is a single renderable and wrap it into a sequence before looping:
{% set content = content and content is not sequence ? [content] : content %}
However, we will need to wait the move to 1.1.x branch because the 1.0.x branch is still supporting Drupal 9:
This change need to be done everywhere there is a loop on a slot:
components/image_list/image_list.twig:{% for image in images %}
components/image_list/image_list.twig:{% for image in images %}
components/grid_row/grid_row.twig: {% for item in content %}
Active
2.0
Code
Automatically closed - issue fixed for 2 weeks with no activity.