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.