How would you append more data to the same variable in Twig? For example, this is what I’m trying to do in Twig:
var data = "foo";
data += 'bar';
I have figured out that ~ appends strings together in Twig. When I try {% set data ~ 'foo' %} I get an error in Twig.
The
~operator does not perform assignment, which is the likely cause of the error.Instead, you need to assign the appended string back to the variable:
See also: How to combine two string in twig?