Upgrade to Pro — share decks privately, control downloads, hide ads and more …

A basic introduction to Mustache

A basic introduction to Mustache

One of my earlier presentations that I did for the Ruby meetup in Perth. A basic introduction to Mustache.

E14f55d3f939977cecbf51b64ff6f861?s=128

Keith Pitt

August 18, 2011
Tweet

Transcript

  1. Mustache Logic-less templates

  2. @keithpitt Keith Pitt iOS/Web Developer The Frontier Group

  3. What is Mustache? • Mustache is a logic-less templating system

    for HTML, config files, anything really • Lightweight • No if statements, else clauses, or for loops Text
  4. Usage

  5. * {{name}} * {{age}} * {{company}} * {{{company}}} * Keith

    * * &lt;b&gt;TFG&lt;/b&gt; * <b>TFG</b> Tags { “name”: “Keith”, “company: “<b>TFG</b>” } + =
  6. {{#repo}} <b>{{name}}</b> {{/repo}} <b>rails</b> <b>redis</b> Sections { “repo”: [ {

    “name”: “rails” }, { “name”: “redis” } ] } + =
  7. {{^repo}} <em>No Repos!</em> {{/repo}} <em>No Repos!</em> Inverted Sections { “repo”:

    [ ] } + =
  8. <h2>Repos {{! this is a comment }}</h2> Comments

  9. {{ < partial_name_here }} Partials

  10. Support • Ruby • JavaScript • Python • Erlang •

    PHP • Perl • Objective-C • Java • .NET • Android • C++ • Go • LUA • ooc • ActionScript • CoffeeScript • ColdFusion • Scala • Clojure • Fantom • D • node.js
  11. Ruby Example >> require 'mustache' => true >> Mustache.render("Hello {{planet}}",

    :planet => "World!") => "Hello World!"
  12. Examples

  13. None
  14. @keithpitt Thanks for your attention