Git Product home page Git Product logo

mustache.cfc's Introduction

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>

Testing

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

mustache.cfc's People

Contributors

pmcelhaney avatar rip747 avatar dswitzer avatar theyves avatar markmandel avatar seancoyne avatar david-mulder avatar davidgortega avatar awayken avatar daamsie avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.