Search code examples
swig-template

Swig-template delete Whitespaces per default


I am using Swig as the template engine in my project to create XML. To make the XML output look nice I need to add a "-" everytime I use the template functions ({% -%}, {{ -}}, {# -#}).

It would be nice to be able to change the default behavior to always strip whitespace before and after. Is there a setting for this already?


Solution

  • No, there isn't.

    The stripping is done in line 624 in parser.js: https://github.com/paularmstrong/swig/blob/2e0e135ac04da5bf75f79cf8d4498094b3b49d35/lib/parser.js#L624

    The variables stripNext and stripPrev are set to true only if a tag or a variable expression includes this -. If not stripping will not be done. There is no other way.