GithubHelp home page GithubHelp logo

ko.mustache.js's Introduction

#ko.mustache.js

ko.mustache.js is a template engine for knockoutjs. It enables you to use mustache.js template library in place of jQuery.tmpl.

Tested with Knockout v2.1 and mustache.js v0.5.1-dev.

##Usage

Set default template engine to be used by Knockout. Make sure you do that before of your custom Knockout related code (like creating observables, applying bindings etc.).

// Set ko.mustache.js as a template engine for knockout
ko.setTemplateEngine(new ko.mustacheTemplateEngine());

##Example

<html>
<head>
	<title>ko.mustache.js example</title>
	<script type="text/javascript" src="lib/mustache.js"></script>
	<script type="text/javascript" src="lib/knockout-2.1.0.js"></script>
	<script type="text/javascript" src="ko.mustache.js"></script>
	<script>
		ko.setTemplateEngine(new ko.mustacheTemplateEngine());
	</script>
</head>
<body>
	<!-- place for rendered template -->
	<div data-bind='template: "personTemplate"'></div>

	<!-- mustache template -->
	<script id='personTemplate' type='text/html'>
		{{ name }} is {{ age }}
		<button data-bind='click: makeOlder'>Make Older</button>
	</script>

	<!-- knockout model and bindings -->
	<script type='text/javascript'>
		var viewModel = {
			name: 'Martin',
			age: ko.observable(78),
			makeOlder: function () {
				this.age(this.age() + 1);
			}
		};
		ko.applyBindings(viewModel);
	</script>
</body>
</html>

##Copyright

Copyright (c) 2011 Marcin Wtorkowski. License: MIT (http://www.opensource.org/licenses/mit-license.php)

ko.mustache.js's People

Contributors

wtk avatar davidduffett avatar jasonm23 avatar jcapriotti avatar

Watchers

James Cloos avatar Rafique avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.