Simple usage of handlebars In the JavaScript Page Template Library

Source: Internet
Author: User

Simple usage of handlebars In the JavaScript Page Template Library

This article is mainly to share with you the simple usage of Handlebars, a javascript Page Template Library, which can help you easily construct semantic templates. It is very practical and recommended to you.

 

 

Handlebars is a JavaScript Page Template Library that helps you easily build semantic templates.

 

The Code is as follows:


<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN">
<Html>
<Head>
<Title> handlebars </title>
<Meta http-equiv = "keywords" content = "keyword1, keyword2, keyword3">
<Meta http-equiv = "description" content = "this is my page">
<Meta http-equiv = "content-type" content = "text/html; charset = UTF-8">
<Script src = "$ {base}/js/jquery1.11.min. js"> </script>
<Script src = "$ {base}/js/handlebars-v3.0.0.js"> </script>
</Head>
<Body>
<Div id = tt style = 'display: none'>
<Div class = "entry">
<H1 >{{ title }}<Div class = "body" >{{ body }}</div>
</Div>
</Div>
</Body>
<Script type = "text/javascript">
// $ ('# Tt'). before (' <script id = "temp" type = "sfd"> ');
// $ ('# Tt'). after ("</script> ");//
Var source = $ ("# tt" cmd.html ();
// Alert (source );
Var template = Handlebars. compile (source );
Var data = {title: "My New Post", body: "This is my first post! "
};
Var result = template (data); // fill data in the template
Console. log (result );
$ ('# Tt'). before (result );
</Script>
</Html>

 

The example is very simple. For details, refer to the ThinkVitamin article Getting Started with Handlebars. js. I hope you will like it.

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.

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.