如何在swig模板中创build多行stringvariables?

我试图在swig中创build一个多行stringvariables:

{% set myVariable = " multi line string " %} 

然后我login它:

 {% logMyVariable(myVariable) %} 

但我不明白为什么我的variables不显示在几行:

 multi line string 

而我期待:

 multi line string 

你知道我该怎么做吗?

在HTML中,当文本显示时,文本中的新行不会被渲染。 例如,这个HTML:

 <p>Let's split this sentence up onto multiple lines.</p> 

将会像这样渲染:

 Let's split this sentence up onto multiple lines. 

您可能希望将您的log包装在<pre>标记中 ,因为这将保留新的行(以及单词之间的多个空格,在呈现的HTML中也会被忽略):

 <pre>{% logMyVariable(myVariable) %}</pre>