Skip to content

Instantly share code, notes, and snippets.

@ycatch
Last active March 17, 2018 16:01
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 ycatch/b835217ffe64489c347436c1008d0f91 to your computer and use it in GitHub Desktop.
Save ycatch/b835217ffe64489c347436c1008d0f91 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>mustache.js | Usage</title>
<!-- 外部のテンプレートファイルをAjaxで読み込む -->
<!-- Try this on your Web Server -->
<style>
body {
padding: 30px;
}
</style>
</head>
<body>
<div id="target">Loading...</div>
<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/mustache.js/2.2.0/mustache.min.js"></script>
<script>
$(function() {
var obj = {
title: "Mustache",
description: "吾輩は猫である。",
date: function() {
return new Date();
}
};
$.get('template2.mst', function(template) {
var output = Mustache.render(template, obj);
$("#target").html(output);
});
});
</script>
</body>
</html>
<h1>Hello {{title}}</h1>
<div>{{description}}</div>
<div>{{date}}</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment