Pug模板未呈现传递给它的原始HTML [英] Pug template isn't rendering raw HTML passed to it
问题描述
我有一个哈巴狗模板,当在我的网页上单击一个按钮时,该模板就会呈现并显示给用户.我有一个问题,哈巴狗将HTML标签呈现为原始文本,而不是解析文本并将其添加为DOM节点.
I have a pug template that is rendered and shown to the user when a button is clicked on my web page. I have an issue with pug rendering HTML tags as part raw text instead of parsing the text and adding it as a DOM node.
我的哈巴狗模板看起来像:p #{object.property}
,所以尝试将HTML字符串插入到模板中.
My pug template looks like: p #{object.property}
so trying to interpolate an HTML string into the template.
该属性包含一个类似于以下内容的HTML字符串:
The property contains an HTML string that looks like:
<p>Here is some text I'm trying to render</p>
我尝试仅使用#{object.property}
来解决奇怪的渲染问题,即它会在页面中渲染<
并随后显示文本内容.我很确定这是由帕格将<
阅读为纯文本,而将p
作为帕格阅读元素引起的.
I have tried just using #{object.property}
to strange rendering issues where it renders <
in the page followed by the text content. I'm pretty sure this is caused by pug reading the <
as plain text and the p
as a pug element which makes sense.
这是呈现器在呈现的网页上的外观.
This is what the render looks like on the rendered web page.
<
Here is some text I'm trying to render
>Here is some text I'm trying to render
>
我要完成的工作是在pug模板中引用有效的HTML字符串,并将pug渲染为DOM节点.
What I'm trying to accomplish is having reference to a valid HTML string in my pug template and have pug render it as a DOM node.
不幸的是,没有标签的HTML字符串是不可能的.
Having the HTML string without tags is unfortunately out of the question.
任何回复都值得赞赏.
注意:使用Pug 2.0.0-beta-11
Note: Using Pug 2.0.0-beta-11
推荐答案
为了在传递给模板的字符串中保留HTML,您需要使用未转义的字符串插值.您需要使用感叹号代替括号前的数字符号.所以#{object.property}
应该是!{object.property}
In order to preserve HTML in a string passed to the template, you need to use unescaped string interpolation. Instead of the number sign before brackets, you need an exclamation point. So #{object.property}
should be !{object.property}
这篇关于Pug模板未呈现传递给它的原始HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!