Matheus Oliveira
Matheus Oliveira

Reputation: 627

How to add space between variables in twig template?

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?

Upvotes: 2

Views: 16500

Answers (5)

Nick Tredwell
Nick Tredwell

Reputation: 11

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

Upvotes: 1

Jo.
Jo.

Reputation: 74

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)

Upvotes: 2

j gaub
j gaub

Reputation: 81

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

{{ firstname }}{{ " " }}{{ lastname }}

Upvotes: 8

Kaveh Yzd
Kaveh Yzd

Reputation: 117

you can use

{{ civilite~" "~nom~" "~prenom  }}

Upvotes: 1

Jordan D
Jordan D

Reputation: 728

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

how about

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

Upvotes: 14

Related Questions