0

Forced to piggyback on WPML's twig setup in a wordpress plugin. So stuck with their setup and twig 1.32.0.

Is there some way I can force twig to keep whitespace between variables?

{% set foo = "foo" %}
{% set bar = "bar" %}
<p>{{ foo }} {{ bar }}</p>

Expected output:

foo bar

Acctual output:

foobar

I really don't want to use &nbsp . I can't change how WPML has setup twig so i need something I can use in my template directly to fix this.

  • 1
    seems to work just fine here: https://twigfiddle.com/rgdrk1 is ` ` an option: `

    {{ foo }} {{ bar }}

    ` or what you can also try is: `{{ foo ~ ' ' ~ bar }}`
    – caramba Jun 17 '21 at 11:52
  • Yes, I expect it to work in a clean environment , but I think WPML has set twig to stip all whitespace. So I need to unset it for my templates. – Bobo Wieland Jun 17 '21 at 11:56
  • > you can also try is: {{ foo ~ ' ' ~ bar }} That is something I can work with that is much more readable than &nbsp! Thanks – Bobo Wieland Jun 17 '21 at 11:58
  • 1
    You can fix this by adjusting the [lexer](https://stackoverflow.com/questions/42123721/prevent-twig-from-removing-a-space-before-a-variable) as you were forced to downgrade your twig version – DarkBee Jun 17 '21 at 12:00
  • Thank you @DarkBee . I could in fact use twig 1.43.1 with out causing conflicts with WPML. Both your suggestions was most useful – Bobo Wieland Jun 18 '21 at 12:37

0 Answers0