0

I am working on budget upgrade of legacy Silex 1.x and PHP5 based application to Silex 2.3 with PHP7.4 I am well aware that Silex is dead and, ideally, app should be migrated to Symfony but this is not possible for now due to time and budget limitations. So far everything is okay with exception of one problem that drives me insane: Twig always strips spaces around it's statements.

For example if I have in a template:

HELLO {{ name }}   !

Where name has value of 'World', then the result will always be HELLOWorld! All spaces around the brackets will be stripped away.

This behavior did not happen with old Silex environment, it does not happen with new twig 3.0 environment in another project either.

It is almost as if twig uses the whitespace trimming logic (the one with '-' character) by default with exception of the fact that it does not remove line breaks.

Did anyone encounter this and do you know how to solve this issue?

Thanks

Don
  • 59
  • 2
  • 4
    Does this answer your question? [Twig problem with php 7.4 in write variable](https://stackoverflow.com/questions/59248533/twig-problem-with-php-7-4-in-write-variable) – DarkBee Aug 16 '20 at 18:37
  • Thank you, thank you, thank you! It indeed does! Requires patching on Twig but better such is life. – Don Aug 16 '20 at 18:57
  • Yeah had the same thing when we switched up the php version – DarkBee Aug 16 '20 at 19:08

1 Answers1

0

Same problem here wit an old project using Twig 1.x with no options to update. So far, we have solved the problem inserting the html code for spaces where necessary in the templates. I mean:

HELLO   {{ name }}   !

UPDATE: As mentioned on the comments, this question is a possible duplicate of (or closely related to) Twig problem with php 7.4 in write variable. I posted my solution there and here just hoping to be reached more easily.

jap1968
  • 7,747
  • 1
  • 30
  • 37