Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
J

jquery-Mustache

> 编程语言
Open source

Mustache templating plugin for jQuery

197 stars0 likes2 views
WebsiteGitHub

About

Mustache templating plugin for jQuery

jQuery-Mustache - A jQuery Plugin for working with Mustache.js

jQuery-Mustache.js is a jQuery Plugin which makes working light work of using the Mustache templating engine via a bit of jQuery magic.

Installation

jQuery-Mustache has two dependencies:

  • jQuery 1.5 or later.
  • Mustache.js 0.4 or later.

As with all jQuery plugins, just ensure that you load jQuery before you load jQuery-mustache.js, for example:

Usage

Lets get down to it and load an external template and then render it.

var viewData = { name: 'Jonny' };
$.Mustache.load('./templates/greetings.htm')
	.done(function () {
    	$('body').mustache('simple-hello', viewData);
    });

In the above example we are loading an external template HTML file (greetings.htm) and, once it's finished loading we render it out replacing the contents of the body element. Your templates should be defined in a script block in the external HTML file where the script block's id will define the template's name, eg:

You can also add templates directly either as String literals or by referencing other DOM elements, eg:

$.Mustache.add('string-template', '

Hi, {{name}}, this is an inline template ');

// These two are identical, the latter just provides a terser syntax.
$.Mustache.add('dom-template', $('#dom-template').html());
$.Mustache.addFromDom('dom-template');

If you prefer to have all your templates stored in the DOM (as opposed to loading them from external files) then you can just call $.Mustache.addFromDom() without any arguments, this will read in all templates from any `

$.Mustache.load('templates.htm')
	.done(function () {
		// Renders the `webcontent` template and the `footer-fragment` template to the page.
		$('body').mustache('webcontent', { year: 2012, adjective: 'EPIC' }); 
	});

Check out the included example file for other usage scenarios.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

JavaScript

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言