Source: Internet
Author: User


Excellent blog: http://www.cnblogs.com/iyangyuan/archive/2013/12/12/3471227.html

Official website: http://handlebarsjs.com/

Note the point:

Nested loops are supported:

This refers to the current context

Index usage in loops: @index (starting from 0)

{{AddOne @index}}
        Register a handlebars Helper, which is used to index +1, because the default is 0-based        handlebars.registerhelper ("AddOne", function (index,options) {           return parseint (index) +1;        });

Extension methods:

Handlebars.registerhelper is used to define helper, it has two parameters, the first argument is the helper name, and the second parameter is a callback function to execute the core business logic. The callback function can have at least 1 parameters, the last parameter is fixed, called the options, if added this parameter, it is a block, block-level helper, there is a certain grammatical structure, called when the # number, like if.

With regard to the use of options, it is this usage that is known by the side dishes, return Options.fn (this), indicating that the condition continues to execute, that is, the code between {{#compare}} and {else}} is executed; return Options.inverse (this); indicates that the condition is not met, that is, the code between {{else}} and {{/compare}} is executed.

Such as:

        Register a comparison size helper to determine if V1 is greater than v278         handlebars.registerhelper ("Compare", function (v1,v2,options) {           if (v1 >V2) {             //Meet add continue to execute Bayi             return Options.fn (this);           }else{83             //Do not meet condition execution {{else}} partial             return Options.inverse (this);           }86         });

HTML Encoding:

The contents obtained through {{}} are encoded, that is, if the contents of the extract contain HTML tags, they will be transcoded into plain text and will not be parsed as HTML, actually doing something like this: replace < with &lt;.

This is good, both to display HTML code and to avoid XSS injection. This feature is very useful when doing code presentation.

But sometimes we may need to parse the HTML, do not transcode, it is easy to replace {{}} with {{}}}.


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.

Tags Index: