zoukankan      html  css  js  c++  java
  • EJS interpolation syntax : pass data to templates

    refer to: https://www.udemy.com/course/the-web-developer-bootcamp/

    https://ejs.co/#docs

    Tags

    • <% 'Scriptlet' tag, for control-flow, no output
    • <%_ ‘Whitespace Slurping’ Scriptlet tag, strips all whitespace before it
    • <%= Outputs the value into the template (HTML escaped)
    • <%- Outputs the unescaped value into the template
    • <%# Comment tag, no execution, no output
    • <%% Outputs a literal '<%'
    • %> Plain ending tag
    • -%> Trim-mode ('newline slurp') tag, trims following newline
    • _%> ‘Whitespace Slurping’ ending tag, removes all whitespace after it

    example

     embed js in html(.ejs file)

    <body>
        <h1>《出现又离开》<%= 0202 + 1%>
        </h1>
        <p>
            试探未知和未来 <br>
            相信那胡言一派 <br>
            当天空暗下来<br>
            当周围又安静起来<br>
            当我突然梦里醒来<br>
            就等着太阳出来<br>
        </p>
    </body>

    generate random number

    random.ejs
    
    <body>
        <h1>Your random number is : <%= Math.floor(Math.random()*10) + 1 %>
        </h1>
    </body>
    index.js

    app.get('/random', (req, res) => { res.render('random.ejs') })

    run nodemon index.js. ------>

    the normaler way to use math: passing data to templates

    index.js

    app.get('/random', (req, res) => { const num = Math.floor(Math.random() * 10) + 1 res.render('random.ejs', {bubble: num}) })
    random.ejs
    
    <body>
        <h1>Your random number is : <%= bubble %>.  //match the object name defined in index.js
        </h1>
    </body>
  • 相关阅读:
    [转载]四大Java EE容器
    [转载]javaEE规范和SSH三大框架到底有什么关系
    javaee包含的服务和组件
    Java类文件最大限制
    oracle给字段添加描述
    apache commons工具包
    redis教程
    git学习
    编程人物
    程序员必须了解的5大编程准则
  • 原文地址:https://www.cnblogs.com/LilyLiya/p/14365151.html
Copyright © 2011-2022 走看看