2

It's a pretty simple question, but I didn't find the answer yet.

This code:

{{ civilite }}{{ nom }}{{ prenom }}

Prints MRJOHSONBarry

I want to add space between the variables, how could I do it?

Guillaume Racicot
  • 39,621
  • 9
  • 77
  • 141
Matheus Oliveira
  • 587
  • 3
  • 10
  • 33
  • 1
    _how could I do it?_ - ... adding a space between the variables. `{{ civilite }} {{ nom }} {{ prenom }}` – Federkun Nov 01 '16 at 17:27
  • it didn't worked :x I also tried {{' '}} – Matheus Oliveira Nov 01 '16 at 17:28
  • Does anyone know why adding actual spaces doesn't work? I have a site where this randomly stopped working so I'm having to go through and add `{{ " " }}` everywhere. Maybe related to me recently upgrading to PHP 7.4? – Visualise Mar 05 '20 at 07:31
  • Never mind, I probably need to update Twig for PHP 7.4 support. See https://github.com/twigphp/Twig/issues/3248 – Visualise Mar 05 '20 at 07:35

5 Answers5

13

If {{ civilite }} {{ nom }} {{ prenom }} doesn't work...

how about

{{ civilite }} {{ nom }} {{ prenom }}?
Jordan D
  • 718
  • 7
  • 21
8

I don't know if it's good but I simply use this. Tell me if I'm right :

{{ firstname }}{{ " " }}{{ lastname }}
j gaub
  • 81
  • 1
  • 4
1

you can use

{{ civilite~" "~nom~" "~prenom  }}
Kaveh Yzd
  • 119
  • 1
  • 12
1

I think the concatenation is the right choice here, when it's only for variable :

{{ var ~ " " ~ var2 }}

But when it's for variable and string, I guess that the 1rst choice would be enough :

{{ var }} My string

instead of {{ var ~ " My string" }} (Not if you want apply filter on the string)

Jo.
  • 64
  • 1
  • 3
1

I just ran into the problem of needing   on Twig v2.7.4 and cured it by moving to v3.1.1