{{ mustache }} for ColdFusion
ColdFusion HTML
Pull request Compare This branch is 61 commits ahead, 1 commit behind pmcelhaney:master.
Latest commit 1b19a3d Aug 10, 2016 @rip747 Implement RaiseError initialization arguments
This change implements a RaiseError argument when initializing
Mustache which will raise a `Mustache.TemplateMissing` if a
template (or partial) is missing from the file system, which is
that last resort in the lookup order.

The argument excepts a boolean for turning the feature on/off,
default is on.

When turned off, the error will be silenced and an empty string
will be returned for the missing template.



Chris Wanstrath's Mustache templates for ColdFusion.


Mustache is a single component. To install, download the Mustache.cfc file from the mustache directory.

Basic Usage

<cfset mustache = createObject("component", "Mustache").init()>
<cfset template = "Hello, {{thing}}!">
<cfset context = structNew()>
<cfset context['thing'] = 'World'>

<cfoutput>#mustache.render(template, context)#</cfoutput>

Creating Views

Given a template named Winner.mustache:

Hello {{name}}
You have just won ${{value}}!
Well, ${{taxed_value}}, after taxes.

And a view named Winner.cfc:

<cfcomponent extends="Mustache">
  <cffunction name="taxed_value">
    <cfreturn this.value * 0.6>

You can render the view like so:

<cfset winner = createObject("component", "Winner")>
<cfset winner.name = "Patrick">
<cfset winner.value = "1000">
<cfset winner.in_ca = true>


Hello Patrick
You have just won $1000!
Well, $600, after taxes.

A custom tag is also included so you can render templates like so:

<cfset context = {
    name = "Patrick",
    value = 1000,
    in_ca = true,
    taxed_value = 600
} />

<cfimport taglib="/path/to/mustache/dir" prefix="stache" />
<stache:mustache context="#context#">
Hello {{name}}
You have just won ${{value}}!
Well, ${{taxed_value}}, after taxes.


To run the files in the tests folder you first need to download and install MXUnit. MXUnit is not required to run Mustache.cfc