npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

jquery-mustache-earlymarket

v1.0.0

Published

Plugin for mustache usage with jquery

Downloads

245

Readme

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:

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

<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js"></script>
<script src="https://raw.github.com/jonnyreeves/jquery-Mustache/master/jquery.mustache.js"></script>
<script src="https://raw.github.com/janl/mustache.js/master/mustache.js"></script>

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:

<script id="simple-hello" type="text/html">
    <p>Hello, {{name}}, how are you?</p>
</script>

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

$.Mustache.add('string-template', '<p>Hi, {{name}}, this is an inline template<p>');

// 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 <script type="text/html" /> blocks in your markup.

There are two ways to render a Mustache template, either via the global $.Mustache.render() method or via the jQuery mustache selector:

$.Mustache.render('my-template', viewData);		// Returns a String (the rendered template content)
$('#someElement').mustache('my-template', viewData);	// Returns a jQuery selector for chaining.

The jQuery mustache selector defaults to appending the rendered template to the selected element; however you can change this behaviour by passing a method in the options argument:

// Replace the contents of #someElement with the rendered template.
$('#someElement').mustache('my-template', viewData, { method: 'html' });

// Prepend the rendered Mustache template to #someElement.
$('#someElement').mustache('my-template', viewData, { method: 'prepend' });

The mustache selector also allows you to pass an Array of View Models to render which makes populating lists a breeze:

// Clear #someList and then render all the viewModels using the list-template.
$('#someList).empty().mustache('list-template', viewModels);

To help you debug you can fetch a list of all registered templates via $.Mustache.templates() and when you're done, you can call $.Mustache.clear() to remove all templates.

jQuery-Mustache plays nicely with partials as well, no muss, no fuss, just drop the partial into your template, ensure that it's been loaded and jQuery-Mustache will take care of the rest:

<!-- Templates.htm -->
<script id="footer-fragment" type="text/html">
	<p>&copy; Jonny {{year}}</p>
</script>
<script id="webcontent" type="text/html">
	<h1><blink>My {{adjective}} WebSite!</blink></h1>
	
	{{! Insert the `footer-fragment` template below }}
	{{>footer-fragment}}
</script>

$.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.