en.javascript.info/02-ui/05-widgets/04-template-lodash/index.html
Ilya Kantor f301cb744d init
2014-10-26 22:10:13 +03:00

29 lines
552 B
HTML
Executable file

<!DOCTYPE html>
<html>
<body>
<script src="http://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.js"></script>
<script type="text/template" id="menu-template">
<div class="menu">
<span class="title"><%-title%>
<ul>
<% items.forEach(function(item) { %>
<li><%-item%></li>
<% }); %>
</ul>
</div>
</script>
<script>
var tmpl = document.getElementById('menu-template').innerHTML;
var compiled = _.template(tmpl);
var result = compiled({ title: "Заголовок" });
document.write(result);
</script>
</body>
</html>