JavaScript page Template Library handlebars simple usage _javascript tips

Source: Internet
Author: User

Handlebars is a JavaScript page template library that helps you easily build semantic templates.

Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >
<title>handlebars</title>
<meta http-equiv= "keywords" content= "keyword1,keyword2,keyword3" >
<meta http-equiv= "description" content= "This are 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>
<body>
<div id=tt style= ' Display:none ' >
<div class= "Entry" >
<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"). html ();
alert (source);
var template = handlebars.compile (source);
var data = {title: ' My New Post ', body: ' This is my post! '
};
var result = template (data);//fill in the template
Console.log (result);
$ (' #tt '). before (result);
</script>

The example is very simple, specific details can refer to thinkvitamin article Getting started with handlebars.js, I hope you can enjoy.

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.