ejs
EJS is a simple templating language that lets you generate HTML markup with plain JavaScript. No religiousness about how to organize things. No reinvention of iteration and control-flow. It’s just plain JavaScript.
迭代
the process of repeating a mathematical or computing process or set of instructions again and again, each time applying it to the result of the previous stage
(computer science) executing the same set of instructions a given number of times or until a specified result is obtained
religiousness虔诚
the quality of being extremely conscientious
conscientious一丝不苟的,认真的
Someone who is conscientious is very careful to do their work properly.
- Example
1 | <% if (user) { %> |
- Tags
1 | <% 'Scriptlet' tag, for control-flow, no output |
- Includes
Includes are relative to the template with the include call. (This requires the ‘filename’ option.) For example if you have “./views/users.ejs” and “./views/user/show.ejs” you would use <%- include(‘user/show’); %>.
You’ll likely want to use the raw output tag (<%-) with your include to avoid double-escaping the HTML output.
1 | <ul> |
- Layouts
EJS does not specifically support blocks, but layouts can be implemented by including headers and footers, like so:
1 | <%- include('header'); -%> |