【笔记】EJS学习笔记

前言

Embedded JavaScript (EJS) is a web templating system or templating language that allows developers to code HTML markup with simple JavaScript.(维基百科)

下载依赖

1
npm install ejs

定义EJS模板

1
<h1></h1>

注释

1
<%# 注释 %>

输出变量

  • 转译HTML
1
<%= key %>
  • 不转译HTML
1
<%- key %>

执行JS

1
2
<% if(true) { %>
<% } %>

渲染EJS模板

1
2
3
4
5
const ejs = require("ejs");

ejs.renderFile("", { key: "value" }, function (error, result) {
...
});

完成