Render a variable as HTML in EJS

前端 未结 3 2013
花落未央
花落未央 2020-11-28 02:17

I am using the Forms library for Node.js (Forms), which will render a form for me on the backend as so:

var signup_form = forms.create({
    username: fields         


        
3条回答
  •  囚心锁ツ
    2020-11-28 02:38

    October 2017 update

    The new ejs (v2, v2.5.7) development is happening here: https://github.com/mde/ejs The old ejs (v0.5.x, 0.8.5, v1.0.0) is available here https://github.com/tj/ejs

    Now with ejs you can do even more. You can use:

    • Escaped output with <%= %> (escape function configurable)
    • Unescaped raw output with <%- %>
    • Newline-trim mode ('newline slurping') with -%> ending tag
    • Whitespace-trim mode (slurp all whitespace) for control flow with <%_ _%>
    • Control flow with <% %>

    So, in your case it is going to be <%- variable %> where variable is something like

    var variable = "text here 
    and some more text here";

    I hope this helps someone.

提交回复
热议问题