Video Address: https://www.cctalk.com/v/15114923888328View Nunjucks
The Rainbow is the Covenant of God and Man, and God will not use the flood to extinguish the man.
The " template engine " needs to be used when the client and the server communicate with each other, and the data that is passed is eventually displayed in the view.What is a template engine?The template engine is created to separate the user interface from the business data
We're all familiar with node. JS and you don't have to introduce too much.The homepage of each project:node.js:http://nodejs.orgExpress:http://expressjs.comnunjucks:http://mozilla.github.io/nunjucks/Supervisor:https://github.com/isaacs/node-supervisorNunjucks is inspired by Python's Jinja2 template, and if you have a Django template enthusiast using Python, you can try swig.Replace the default Jade because it prefers this style of not forcing indentat
Controllers folder to add all the interface files to the route ├──rest.js package RESTAPI returns data processing, simplifying API notation--rest methods ├──templating.js package template engine loading view template file,--render method ├──static-file.js Package static file loading method │ ├──controllers All interface files under this directory, such as: ├──api.js Restapi interface ├──index.js Home Interface ├── ... ├──view You place the view template file under this directory, you ca
engine that can bind data directly to the DOM, including some great features such as HTML templates and JS view logic. Supports IE9 +, Chrome, Firefox, iOS, Android, Etc.
4) Underscorejs
Underscore is a JavaScript library that provides a large number of functional programming assistants without the need to expand any built-in objects.
5) Embeddedjs
EJS uses a client template to clear HTML code from JavaScript. After the code is compiled, the JavaScript code becomes more neat and organized.
6) D
can span multiple rows:
$("#warning").html(` Watch out! Unauthorized hockeying can result in penalties of up to ${maxPenalty} minutes.`); $("#warning").html(` Watch out! Unauthorized hockeying can result in penalties of up to ${maxPenalty} minutes.`);
All spaces, line breaks, and indentation in the template string will be output to the result string as is.
Let's take a look at what the template string cannot do:
Special characters are not automatically escaped. To avoid cross-site scripting v
have to repel that feeling.The future of the anti-apostropheOf course, template strings are not everything:
They do not automatically escape special characters for you, and in order to avoid cross-site scripting vulnerabilities, you should treat non-confidence data in a special way as you would when stitching a normal string.
They don't work well with internationalized libraries (which can help you provide different languages for different users), and template strings don't format
in the template string are output to the result string as-is.
Let's look at what the template strings can't do:
Special characters are not automatically escaped, and in order to avoid cross-site scripting vulnerabilities, you still need to be careful with untrusted data, as with normal strings.cannot be used in conjunction with internationalized libraries, and does not deal with numbers, dates, etc. in special language formats.is not a substitute for a template engine (such as mustache or
register the Angularjs template in $templatecache
Gulp-jade-jade converted to HTML.
The Gulp-handlebars-handlebars template is converted into JavaScript.
The Gulp-hb-handlebars template is converted into HTML.
The gulp-nunjucks-nunjucks template is converted into JavaScript.
The gulp-dustjs-dust template is converted into JavaScript.
The Gulp-riot-riot template is converted into JavaScript.
Gulp-markdown-m
In the previous section we created a WebSocket application with the WS module. But it can only respond to echo:xxx messages in a simple way, and it belongs to the Hello, world-level app.
To create a real websocket application, first of all, there must be an MVC-based Web application, which is the web that we created in front of KOA2 and Nunjucks, on which the websocket is added in order to be complete.
Therefore, the goal of this section is to create
Directly with the script Introduction file: is used render to render files directly, which supports inheritance (extends) and include templates. Use the path before you need to configure the file: true }); Nunjucks.render (' index.html ', {foo: ' Bar '});On the node side, the ‘views‘ path relative to the current working directory (working directory). On the browser side is a relative URL, preferably specified as an absolute path (for example ‘/views‘ ). The directory structure of the project
the page faster. To feel the benefits of streaming, you need to use a template engine that supports streaming. In addition, templates that support asynchronous rendering (such as Marko, Dust, and Nunjucks) can even output responses before the View model is constructed, thus bringing more performance improvements.Centralized configurationNot all configurations are bad, but unnecessary configurations are definitely bad. If the configuration is not need
, which can now be developed using node. js!Developing a Web server side with node. JS has several notable advantages:One is the back-end language is also JavaScript, previously mastered the front-end JavaScript developers, now can write the backend code at the same time;Second, the front and back end of the unified use of JavaScript, there is no barrier to switch language;Three is the speed fast, very fast! This is due to the innate asynchronous nature of node. js.In just a few years after the
used?
Well, it's too long to be useless, don't remember.
jtemplates, jqote or PURE?
Well, I don't remember, anything else?
Transparency? JSRender? Markupjs? Knockoutjs? This one supports two-way binding.
Do you have anything else?
Platesjs? Jquery-tmpl? Handlebars? Some people are using it.
Kind of like. What's the last one that looks like?
mustache, underscore? I remember that even Lodash had a template engine, but it was the 2014 thing.
/.
Steps for using the source code:
1. Install node;
2. install thinkjs, npm install thinkjs @ 2-g -- verbose, if slow, you can use npm install thinkjs @ 2-g -- registry = https://registry.npm.taobao.org -- verbose;
3. Installation depends on npm install;
4. Run the program npm start;
The combo interface in the source code is self-implemented by myself, of course, this combo everyone can also use outside mature combo solution; Template selected Nunjunks, powerful template engine (http://mozilla
: Don't worry. I just want to tell you what you can use.
Q: Stop!
A: I mean, even if you only want to use a template engine, we recommend using typescript + systemjs + Babel.
Q: Well, we recommend a template engine!
A: There are many. Which one are you familiar?
Q: Well, I used it a long time ago. I can't remember it.
A: jtemplates? Jqote? Pure?
Q: Have you heard of this?
A: transparency? Jsrender? Markupjs? Knockoutjs?
Q: Are there any more?
A: platesjs? Jquery-tmpl? Handlebars?
The steps are as follows:1. Installation Dependence: SPM INSTALL-E2. Compiling: SPM Build(The compiled items will be placed in the trunk-dist)3. Release: SPM app-d(Will come out an export port, typically: 4745)4, enter in the browser: http://localhost:4745/examples/index.html can be runIf something goes wrong, it's a bug, and you're done with 2, 3, 4, three steps.For example:1, the component structure is as follows:2. Code: Package.jon configuration information (some dependencies):"Dependencies"
? Markupjs? Knockoutjs? This one supports two-way binding.
Do you have anything else?
Platesjs? Jquery-tmpl? Handlebars? Some people are using it.
Kind of like. What's the last one that looks like?
Mustache, underscore? I remember that even the Lodash had a template engine, but it was the 2014 thing.
Well, maybe a new library?
The Jade? Dustjs?
No use.
Dotjs? EJS?
No use.
Nunjucks?
two-way binding.
Do you have anything else?
Platesjs? Jquery-tmpl? Handlebars? Some people are using it.
Kind of like. What's the last one that looks like?
mustache, underscore? I remember that even Lodash had a template engine, but it was the 2014 thing.
Well, maybe a new library?
The
Jade? Dustjs?
No use.
Dotjs? EJS?
No use.
nunjucks? Ect?
No use. I can't remember, if you say
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.