Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add compiled templates overview and examples to readme #280

Merged
merged 1 commit into from
Dec 11, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,32 @@ According to [ctemplates](http://google-ctemplate.googlecode.com/svn/trunk/doc/h

Custom delimiters may not contain whitespace or the equals sign.

### Compiled Templates

Mustache templates can be compiled into JavaScript functions using `Mustache.compile` for improved rendering performance.

If you have template views that are rendered multiple times, compiling your template into a JavaScript function will minimise the amount of work required for each re-render.

Pre-compiled templates can also be generated server-side, for delivery to the browser as ready to use JavaScript functions, further reducing the amount of client side processing required for initialising templates.

**Mustache.compile**

Use `Mustache.compile` to compile standard Mustache string templates into reusable Mustache template functions.

var compiledTemplate = Mustache.compile(stringTemplate);

The function returned from `Mustache.compile` can then be called directly, passing in the template data as an argument (with an object of partials as an optional second parameter), to generate the final output.

var templateOutput = compiledTemplate(templateData);

**Mustache.compilePartial**

Template partials can also be compiled using the `Mustache.compilePartial` function. The first parameter of this function, is the name of the partial as it appears within parent templates.

Mustache.compilePartial('partial-name', stringTemplate);

Compiled partials are then available to both `Mustache.render` and `Mustache.compile`.

## Plugins for JavaScript Libraries

mustache.js may be built specifically for several different client libraries, including the following:
Expand Down