Mustache templates in Grails
JavaScript Groovy
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
grails-app
scripts
src
test/unit/org/grails/plugins/mustache
web-app
.gitignore
MustacheGrailsPlugin.groovy
README.textile
application.properties

README.textile

Mustache Plugin

Integrate Mustache into your Grails project.

Mustache provides Logic-less templates that are a great tool for HTML layout, especially in the context of building javascript powered pages within a web browser. Now, thanks to mustache.java, you can interpret Mustache templates from the server as well.

This plugin serves to enable both server-side and client-side use of Mustache while maintaining a DRY methodology (i.e. you can use the same Mustache templates on the client and server).

Tags

Two tags are provided in the “mustache” namespace; render and layoutTemplates

mustache:render

Renders inline Mustache template code or Mustache template files server-side. Inline Mustache templates can also be written as script elements within the page for use by javascript.

attributes

  • model: (required) The object instance to use as the data model for the template.
  • tid : The Document id to use for a script element for use by javascript
  • href : The path, relative to server root, of a Mustache template file.

mustache:layoutTemplates

Renders script elements for each of the inline templates that were given a tid attribute. In practice, this is placed near the closing tag for the body div element.

Examples

Example: Inline mustache with script generation

<mustache:render model="${user}" tid="user-greeting">
  Hello {{fullname}}. 
  {{#isLoggedIn}}
    We're glad you logged in.
  {{/isLoggedIn}}
</mustache:render>
...
<mustache:layoutResources />

Example: Using href

In web-app/tmplates/wax.mustache

Hello {{fullname}}. 
{{#isLoggedIn}}
  We're glad you logged in.
{{/isLoggedIn}}

In the GSP

<mustache:render model="${user}" href="/templates/wax.mustache"