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

后端 未结 3 882
温柔的废话
温柔的废话 2020-12-09 17:24

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
        

        
相关标签:
3条回答
  • 2020-12-09 17:34

    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}
    
    0 讨论(0)
  • 2020-12-09 17:48

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

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

    0 讨论(0)
  • 2020-12-09 17:54

    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.

    0 讨论(0)
提交回复
热议问题