How to insert raw HTML in Pug file (not include external HTML file)

别说谁变了你拦得住时间么 提交于 2019-12-18 13:09:35

问题


So what I want is to put some multiline HTML into a Pug file and can't find anywhere how to do this.

Example:

html
    head

    body
        <div><a href="lala"> blabla </a></div>

        p hihuhohoo

回答1:


Pug text can include HTML. Just force it as text, and it should parse:

html
    head

    body
        | <div><a href="lala"> blabla </a></div>

        p hihuhohoo

Also, you were using backslashes, not forward slashes, to close elements.




回答2:


This is a tested example with passing variables with raw html to the pug file:

yourSourceFile.js

const p1 = 'This server uses a <a href="https://pugjs.org/api/getting-started.html" target="_blank">pug template</a> for the html output'
res.render('yourTemplateFile', { title: 'Hey', p1 })

yourTemplateFile.pug

html
  head
    title= title
  body
    p
      | !{p1}



回答3:


I was only able to do this by encoding < and >

div
  | &#60;script src="https://mydomain.io/script.js"&#x3E;&#60;/script&#x3E;


来源:https://stackoverflow.com/questions/27107451/how-to-insert-raw-html-in-pug-file-not-include-external-html-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!