Skip to content

Instantly share code, notes, and snippets.

@akifumi-kamata
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akifumi-kamata/aa78cbabb66f7fb9661b to your computer and use it in GitHub Desktop.
Save akifumi-kamata/aa78cbabb66f7fb9661b to your computer and use it in GitHub Desktop.
handlebarsjs-sample01
<!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