Twig {% set %} variables no longer render in Element CSS

Variables defined with {% set %} in Element CSS are no longer output when the CSS is compiled. The same Twig in a Raw Content element still renders correctly, so Twig itself is working. This used to work in an earlier version, so I believe it’s a regression.

Not sure exactly what version changed this behaviour, but I have been able to confirm it working previously in 6.5.8

Steps to reproduce

  1. Add a Div element to a page in Cornerstone.
  2. In the Element CSS add:
{% set colour = "blue" %}

$el {
  background-color: {{ colour }};
}

In 6.5.8 this outputs background-color: blue;
image

However in 6.9.6 this no longer works, as it tries to set background-color to a CSS var, but the var is not set.

Hey @connexxions,

Thank you for reporting. While this is being lined up for investigation by our development team, please try the workarounds below:

If you need to bypass CSS variable extraction or define reusable values in Element CSS:

  1. Set values using CSS Custom Properties directly instead of Twig {% set %}:
    $el {
      --colour: blue;
      background-color: var(--colour);
    }
    
  2. If Twig logic/conditionals are required to determine the value, generate the CSS declaration inside the Twig tag rather than interpolating into CSS syntax:
    {% set colour = "blue" %}
    {% set rule = "$el { background-color: " ~ colour ~ "; }" %}
    {{ rule|raw }}
    
    (Wrapping the output so {{ ... }} isn’t parsed as a standalone CSS property value prevents the TSS regex from splitting it into a CSS variable).

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.