Drupal Twig Stubs
Drupal Twig StubsCategory
Drupal Version
Twig stubs and code-samples to aid your Twig template development.
External Resources
- Twig data stubs (from the Ivan Allen College's web development resources website)
Check for (non-)empty fields
Check for (non-)empty fieldsCategory
Drupal Version
Satisfies a comment on drupal.org:
Someday I would like to spend the time to make a list of the various field types and the best way to check whether they are empty so I can stop Googling this thread every few months.
Basic field
Expensive (render) check
{% if content.field|render is not empty %}
{{ content.field }}
{% endif %}
Note that this can be an expensive (resource-wise) check to make.
Basic check
{% if node.field.value %}
{{ content.field }}
{% endif %}
Entity Reference fields
{% if content.field['#items'].getValue() %}
{{ content.field }}
{% endif %}
Note
This should be compiled over on drupal.org in the near future, anyways.