JS Template engine Handlebars Learning (i)

Source: Internet
Author: User
Tags smarty template

1. Handlebars is a front-end JS template engine that has its own syntax like other template engines such as PHP templates

{$foo}        <--Display simple variable (non-array/ object) PHP smarty template engine div (class//Pug template engine  // handlebars's template engine

2. Basic expressions

1 //The data are as follows:2 {3Title: "XXXXX",4 Person : {5Name: "Jack",6Age:30,7Hobbies: ["Football", "basketball", "Xbox"]8     }9 }Ten<div> One A<div>{{person.name}}</div>//support. Operator represents object properties -<div>{{person/age}}</div>//The same support/operator represents the object properties, but this writing has not been recommended, for official documents do not recommend the wording, be sure to remember not to use. -<ul> the{{#each person.hobbies as |hobby|}} -<li>{{hobby}}</li> -{{/each}} -</ul> +</div>

3. Special characters Disable marking

whitespace//Space, tab, carriage return line

When referencing an illegal identity, you can use the [Reference property, as follows:

1 {{#each articles.[ ). [#comments]}} 2   3   <div>4    {{body}}5   </div>6 {{/each}}

The above loop is the following variable

1 articles[10][' #comments ']

4. Escaping and prohibiting escaping

{  "}<div>    <p> escaped display </p>    {{H1}} </div><div>    <p> Disable escaping, what is output as-is </p> {{{    h1}}}</div>

The output is as follows:

{  "}<div>    <p> escaped presentation </p>    %3ch1% 3egood%3c/h1%3e</div><div>    <p> Forbidden escape, what is output as-is </p>    

Write these first, and the next chapter should learn some helpers and sub-expressions.

JS Template engine Handlebars Learning (i)

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.