简体   繁体   English

如何在树枝模板中的变量之间添加空格?

[英]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打印 MRJOHSONBarry

I want to add space between the variables, how could I do it?我想在变量之间添加空格,我该怎么做?

If {{ civilite }} {{ nom }} {{ prenom }} doesn't work...如果 {{ Civilite }} {{ nom }} {{ prenom }} 不起作用...

how about怎么样

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

I don't know if it's good but I simply use this.我不知道它是否好,但我只是使用它。 Tell me if I'm right :告诉我是否正确:

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

你可以使用

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

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)而不是{{ var ~ " My string" }} (如果你想在字符串上应用过滤器,则不是)

I just ran into the problem of needing  我刚刚遇到了需要 的问题  on Twig v2.7.4 and cured it by moving to v3.1.1在 Twig v2.7.4 上并通过移动到 v3.1.1 来治愈它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM