I have a Form with Symfony 2 with a textarea.
我有一个带有文本区域的Symfony 2的表单。
If the user writes something like this in the textarea
如果用户在textarea中写这样的东西
word1
word2 word3 word4
word5
rest of message
i'm getting the data exactly like this from the form, but without any HTML linebreaks. So if i want to use this text further for sending a email it'll be shown as this
我从表单中获得的数据与此完全一样,但是没有任何HTML换行符。如果我想进一步使用这个文本发送电子邮件它会显示为这个。
word1 word3 word4 word5 rest of message
How can i save the formatting of the Text? Any suggestions?
如何保存文本的格式?有什么建议吗?
2 个解决方案
#2
9
If you are wanting to use this in a Twig template then you should use the nl2br
filter like..
如果您想在一个分支模板中使用这个,那么您应该使用nl2br过滤器。
{{ text|nl2br }} // NOT "bl2br" as I had originally written.
#1
#2
9
If you are wanting to use this in a Twig template then you should use the nl2br
filter like..
如果您想在一个分支模板中使用这个,那么您应该使用nl2br过滤器。
{{ text|nl2br }} // NOT "bl2br" as I had originally written.