8

I'm running into an issue where when I have multiple variables being output into a class attribute, they all get compressed into a single word rather than kept as separate words as originally authored, as in

<div class="className {{ variable1 }} {{ variable2 }}"><div>

At runtime this is being rendered as:

<div class="className variable1variable2"><div>

Any idea what would cause this and how to avoid it?

Cid
  • 14,968
  • 4
  • 30
  • 45
Luis Martins
  • 1,421
  • 2
  • 18
  • 32
  • 1
    This output is weird, since there is a space between the `{{}} {{}}`, it should work as expected. Try to use string concate instead, such as `{{ variable1 ~ ' ' ~ variable2 }}` – Cid May 05 '20 at 09:09
  • Does WordPress’s `the_content` filter run over this? – Gchtr May 05 '20 at 11:30
  • This runs outside the scope of `the_content`. Trying to pinpoint what triggers it as apparently it doesn't affect all sites running PHP 7.4 and Timber. – Luis Martins May 05 '20 at 13:21
  • I don't think this is caused by PHP or Twig specifically - could you expand your question with more information about your environment? Ie, any framework, plugins, type of server etc. My guess is that there's a filter somewhere trying and failing to be helpful. – Bananaapple May 07 '20 at 08:20
  • You may be onto something @Bananaapple, as I don't get consistent behaviour across all sites. Trying to pinpoint the specific set of circumstances that triggers this. – Luis Martins May 18 '20 at 17:05

1 Answers1

7

Faced the same issue on PHP 7.4. Found this fix on GitHub.

So if you're using Twig 1, upgrade it at least to v1.43.0.

If you're using Twig 2, upgrade it at least to v2.10.0. (my case - I had v2.7.4 in the project).

Vladimir
  • 2,461
  • 2
  • 14
  • 18