Last active
March 17, 2018 14:42
-
-
Save ycatch/85e89afed9ad4a6856836a9017b7c70b to your computer and use it in GitHub Desktop.
Handlebars.js: Minimal Templating on Steroids https://handlebarsjs.com/
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> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<title>Template Test</title> | |
<style> | |
body { | |
padding: 30px; | |
} | |
</style> | |
<meta charset="utf-8"> | |
<meta name="description" content="Test for lightweight template engine"> | |
<meta name="author" content="Yutaka Kachi"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<script | |
src="https://code.jquery.com/jquery-1.12.4.min.js" | |
integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" | |
crossorigin="anonymous"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.11/handlebars.min.js"></script> | |
<script type="text/x-handlebars-template" id="template"> | |
<h1>{{name}}</h1> | |
<div>{{description}}</div> | |
<div>{{date}}</div> | |
</script> | |
<script> | |
window.onload = function() { | |
var source = $("#template").html(); | |
var template = Handlebars.compile(source); | |
var values = { | |
name : "Hello World", | |
description : "吾輩は猫である。", | |
date: function() { | |
return new Date(); | |
} | |
}; | |
var html = template(values); | |
console.log(html); | |
$("#contents").html(html); | |
} | |
</script> | |
</head> | |
<body id="contents"></body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment