Use Twig's default filter in place of the ternary operator

Submitted by Charles on Tue, 03/09/2021 - 16:29

Instead of using the ternary operator to set a value or a default if that value doesn't exist, Twig's "default" filter provides a more compact and readable way of doing so. For example:

{% set alignment = alignment ? 'pagination--' ~ alignment : 'pagination--center' %}


{% set alignment = 'pagination--' ~ alignment|default('center') %}