Last active
August 29, 2015 14:06
-
-
Save akifumi-kamata/aa78cbabb66f7fb9661b to your computer and use it in GitHub Desktop.
handlebarsjs-sample01
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="./js/handlebars-v2.0.0.js"></script> | |
<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script> | |
</head> | |
<body> | |
<!-- テンプレート部分 --> | |
<script id="template" type="text/x-handlebars-template"> | |
<h1 class="header">{{title}}</h1> | |
<div>メッセージ:{{message}}</div> | |
</script> | |
<!-- テンプレート部分 --> | |
<!-- ここがテンプレートのデータに置き換わります --> | |
<div id="contents"></div> | |
<!-- テンプレートにデータをセットしHTMLを表示 --> | |
<script > | |
var values = { | |
title: 'Handlebars sample01', | |
message: 'ここにメッセージが表示されます' | |
} | |
var template = Handlebars.compile($('#template').html()); | |
$('#contents').html(template(values)); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment