node. JS Learning Note 11-module engine

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.