Closed Bilge closed 2 years ago
I suggest you do that with separate {% apply %}
tags in a if instead (potentially using a block to reuse the content between 2 places. Allowing expressions there is hard, because the condition is not something we can resolve at compile time to apply the filters in the AST.
I have come across an interesting problem where I want to conditionally apply an
apply
block. Consider the following example adapted from the documentation:This is fine in theory, but suppose we want to toggle between inlining and not based on the presence of a
debug
variable. Twig is not very well equipped to accommodate this. First, we should need to extract our CSS content to aset
tag so they can be inserted at various positions without duplicating the CSS source files list.However, this is invalid since expressions are not parsed in this context.