User login

conditional

Why are twig template comparisons such annoying strings?

A boolean field told in display settings to show as zero or one is actually rendered like this:

" 0 "
" 1 "

That is, a string of the number with a space on either side. Why?

That is from testing using {% set lightbox_class = content.field_lightbox|render %}

At least this works:

{% set lightbox_class = content.field_lightbox|render|trim == 1 ? ' lightbox' %}

So does:

{% set lightbox_class = content.field_lightbox|render|trim ? ' lightbox' %}

Syndicate content