node. js Template Ejs Go

Source: Internet
Author: User

node. JS template Citation Ejs.
Search for a recommended with Ejs most.
Speed ratio: http://www.cnblogs.com/fengmk2/archive/2011/04/28/2031971.html

Ejs speed is not the fastest, the recommendation is probably because of its simple grammatical structure. The code is nested primarily through <%%><%=%>. such as reading logic, but also save a lot of the cost of learning grammar.
There are other custom methods: such as link_to (name, URL), Img_tag (URL), and so on.
JSON can also be supported.
===========
Features of the Ejs:
1, cache function, can cache the parsed HTML template;
2, <% code%> to execute the JavaScript code;
3, <%= code%> will code HTML escape;
4, <%-code%> will not be escaped;
5, support custom tags, such as ' <% ' can use ' {', '%> ' with '} ' instead;
6, provide some auxiliary functions, used in the template
7. Use <%-include filename%> to load other page templates;

Using the example
1, Ejs.compile (str, options); will return the internally parsed function functions
2, Ejs.render (str, options); Returns the parsed string

Some of the options ' parameters are:
1. Cache: If the parsed template is cached, it needs filename as key;
2, FileName: template file name;
3. The context in which the function executes after scope:complile;
4, Debug: The identity is Debeg State, Debug is true will output the generated function content;
5, Compiledebug: Whether the identity is compiled debug, True will generate the parsing process of tracing information, for debugging;
6, client, the identity is used for browser client run, TRUE returns the parsed function functions that can be run separately;
7, open, code at the beginning of the tag, the default is ' <% ';
8, close, code end tag, default to '%> ';
9. Some of the other variables that are provided when parsing the template.
When used in Express, the options parameter is passed in by Response.render, which contains settings in express and user-supplied variable values.

In addition, EJS provides auxiliary functions that are used instead of JavaScript code to make it easier to manipulate data.
1, first, returns the element of the array;
2, last, returns the final element of the array;
3, capitalize, return the first letter uppercase string;
4, Downcase, returns the lowercase of the string;
5, UpCase, returns the uppercase of the string;
6, sort, sorted (object.create (obj). Sort ()? );
7, sort_by: ' prop ', in ascending order according to the specified prop attribute;
8, size, returns the length, that is, the long property, not necessarily an array to line;
9, plus:n, plus N, will be converted to number for operation;
10, Minus:n, minus N, will be converted to number for operation;
11, Times:n, multiplied by N, will be converted to number for operation;
12, Divided_by:n, divided by N, will be converted to number for operation;
13, join: ' Val ', the array with ' Val ' the most delimiter, to merge into a string;
14, Truncate:n, intercepts the first n characters, and returns a copy when it exceeds the length
15, Truncate_words:n, gets the first n Word,word in the string to be separated by a space;
16, Replace:pattern,substitution, string substitution, substitution does not provide will delete the matching substring;
17, Prepend:val, if the operand is an array, it is merged, and the string is added Val in front;
18, Append:val, if the operand is an array, it is merged, and the string is added Val at the back;
19, Map: ' prop ', returns an array of the values in the object array whose properties are prop;
20, reverse, flip array or string;
21, get: ' prop ', get the value of the attribute as ' prop ';
22, JSON, converted to JSON format string

=====================
Template example:

HTML code
  1. <!--Templates/supplies.ejs--
  2. <H1>supplies</H1>
  3. <ul>
  4. <% for (var i=0; I<supplies.length; i++) {%>
  5. <li><%= supplies[i]%></li>
  6. <%}%>
  7. </ul>



The use of Ejs can be referred to:
http://node-js.diandian.com/post/2012-07-03/40029704518
http://blog.csdn.net/lisownjay/article/details/16952723
http://www.csser.com/board/4fddc4f0b28ed7d857001674#/post/4fddc603b28ed7d85700168a
Http://nodeguide.com/index.html

Transfer from http://sunnyhl.iteye.com/blog/1985539

node. js Template Ejs Go

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.