EJS: <%= versus <%-

后端 未结 4 941
死守一世寂寞
死守一世寂寞 2020-12-15 07:26

I\'m using EJS with a Node.js web server I\'m building. I see many EJS examples that sometimes use <%= when outputting HTML or strings, while other examples

相关标签:
4条回答
  • 2020-12-15 07:49

    The version of EJS you're likely using in Node is not the same as the version you see on Google code; in the Node version, <%= escapes the HTML going into the buffer, while <%- does not. source

    0 讨论(0)
  • 2020-12-15 07:59

    With <%= you if would render some variables that holds a string that holds HTML code, it would not render that HTML code but render it as text to avoid cross-site scripting attacks.
    With a minus ( <%- ) you can avoid this, and really render the HTML code.

    0 讨论(0)
  • 2020-12-15 08:06

    <%= *param* %> is use for tranfer data from view to controller and vice versa

    while <%- %> is to include other code

    For my project is

    0 讨论(0)
  • 2020-12-15 08:07

    From http://ejs.co/:

    <% 'Scriptlet' tag, for control-flow, no output
    <%= Outputs the value into the template (HTML escaped)
    <%- Outputs the unescaped value into the template
    
    0 讨论(0)
提交回复
热议问题