Skip to content

dswitzer/Mustache.cfc

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code
This branch is 3 commits ahead, 17 commits behind rip747:master.

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 

Mustache.cfc

Chris Wanstrath's Mustache templates for ColdFusion.

Installation

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}}!
{{#in_ca}}
Well, ${{taxed_value}}, after taxes.
{{/in_ca}}

And a view named Winner.cfc:

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

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>
<cfoutput>#winner.render()#</cfoutput>

Result:

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#">
<cfoutput>
Hello {{name}}
You have just won ${{value}}!
{{##in_ca}}
Well, ${{taxed_value}}, after taxes.
{{/in_ca}}
</cfoutput>
</stache:mustache>

About

{{ mustache }} for ColdFusion

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • ColdFusion 96.7%
  • HTML 3.3%