Replace TWIG render with is not empty checks

Created on 1 April 2024, 9 months ago
Updated 17 April 2024, 8 months ago

Problem/Motivation

Currently the Bootstrap Paragraphs use a lot of TWIG render to identify if a field has content or not. This could be simplified by using is not empty checks in TWIG templates.

Steps to reproduce

Proposed resolution

Replace TWIG |render with is not empty checks based on paragraph entity instead of content render object.

Current code with TWIG render based on content render object:

{% set background_field = content.bp_background|render %}
{% if background_field %}
  {% set classes = classes|merge(column_style_2_classes) %}
{% endif %}

Refactored with TWIG is empty check based on paragraph entity:

{% if paragraph.bp_column_style_2 is not empty %}
  {% set classes = classes|merge(column_style_2_classes) %}
{% endif %}
  • Improve performance because fields are not rendered twice or more during TWIG templating.
  • Cleaner code structure.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ“Œ Task
Status

Fixed

Version

5.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States kerrymick Chicago

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024