JavaScript HTML Handlebars Template

Source: Internet
Author: User

Tags: php flow name render htm var static escape character Tput

/********************************************************************* * JavaScript HTML handlebars Template * Description: * Recently in tossing PHP found that JavaScript can handle things far more than what they are currently dealing with, * found there is a JavaScript HTML framework, so on GitHub with JSON as a configuration, you can freely * combine static site. * * 2017-8-24 Shenzhen Longhua gen Zengjianfeng ************************************************************* *******/First, reference documents:1. TopTenTemplating Engines forJavaScript to Improve and simplify Your Workflow .https://colorlib.com/wp/top-templating-engines-for-javascript/    2. Handlebars http://handlebarsjs.com/    3. Handlebars Getting Started http://handlebarsjs.com/second, the approximate use of the method:1. Variable placeholder: {{variable-name}}<divclass="entry"> <h1>{{title}}</h1> <divclass="Body">{{body}}</div> </div>2. Place template in <script>tag, it feels like a good way to do this when the page is first rendered:<script id="entry-template"Type="text/x-handlebars-template"> <divclass="entry"> <h1>{{title}}</h1> <divclass="Body">{{body}}</div> </div> </script>3. Compile the Template:varSource = $ ("#entry-template"). html (); varTemplate =handlebars.compile (source);    $ (body). HTML (HTML); 4. HTML escape Character: use {{}} to replace escape characters in HTML, which can be avoided by using {{{}}};5. Template comments:<divclass="entry">          {{!--only output author nameifAn author exists--}}          {{#ifAuthor}} <h1>{{author.firstname}} {{author.lastname}}</h1>          {{/if}}        </div>

JavaScript HTML Handlebars Template

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: