Template engine is a tool that generates HTML from a page template according to certain rules.
Problem with template engine:
(1) The page function logic is coupled with the page layout style, and the website becomes more and more difficult to maintain after the large scale.
(2) The complexity of the grammar, for non-technical web designers, the threshold is higher, difficult to learn.
(3) The function is too comprehensive, page designers can be programmed on the page, not conducive to functional division, but also to reduce the efficiency of the template parsing.
The modern template engine is part of MVC, which is strictly part of the view in function partitioning, so the functionality is centered on generating HTML pages.
The function of the template engine is to combine the page template and the data to be displayed to generate an HTML page. It can run on both the server and the client, and most of the time it is parsed into HTML on the server side.
After parsing is completed and then passed to the client, the client cannot even determine whether the page is generated by the template engine.
In the MVC architecture, the template engine is included on the server side. After the controller obtains the user request, obtains the data from the model, invokes the template engine. The template engine takes data and page templates as input, generates an HTML page, and returns it to the controller, which is handed back to the client.
Ejs's label system, 3 kinds:
(1) <% code%>: JavaScript.
(2) <%= code%>: Displays content that has been replaced with HTML special characters.
(3) <%-code%>: Displays the original HTML content.
node. JS Learning Note 11-module engine