Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 64 lines (44 sloc) 1.316 kb
6cd78e9 @bobthecow Usage.
authored
1 Mustache.php
2 ============
3
0e73e66 @bobthecow Updating readme to link to pretty Mustache homepage rather than github p...
authored
4 A [Mustache](http://defunkt.github.com/mustache/) implementation in PHP.
6cd78e9 @bobthecow Usage.
authored
5
27a9b1e @bobthecow Add Travis build status badge.
authored
6 [![Build Status](https://secure.travis-ci.org/bobthecow/mustache.php.png?branch=dev)](http://travis-ci.org/bobthecow/mustache.php)
6cd78e9 @bobthecow Usage.
authored
7
8 Usage
9 -----
10
11 A quick example:
12
faa789a @Aijoona Added syntax highlight.
Aijoona authored
13 ```php
14 <?php
be5cfb3 @bobthecow Rename Mustache_Mustache to Mustache_Engine.
authored
15 $m = new Mustache_Engine;
cb24d63 @bobthecow update README. simplify + link to wiki.
authored
16 echo $m->render('Hello {{planet}}', array('planet' => 'World!')); // "Hello World!"
faa789a @Aijoona Added syntax highlight.
Aijoona authored
17 ```
6cd78e9 @bobthecow Usage.
authored
18
19
96596f4 @bobthecow Update README for 2.0-dev
authored
20 And a more in-depth example -- this is the canonical Mustache template:
6cd78e9 @bobthecow Usage.
authored
21
b277053 @bobthecow Syntax highlighting for mustache in README.
authored
22 ```html+jinja
faa789a @Aijoona Added syntax highlight.
Aijoona authored
23 Hello {{name}}
24 You have just won ${{value}}!
25 {{#in_ca}}
26 Well, ${{taxed_value}}, after taxes.
27 {{/in_ca}}
28 ```
6cd78e9 @bobthecow Usage.
authored
29
5363020 @bobthecow push some whitespace around a bit.
authored
30
96596f4 @bobthecow Update README for 2.0-dev
authored
31 Create a view "context" object -- which could also be an associative array, but those don't do functions quite as well:
fa8c81d @bobthecow Update README to reflect preferred mustache class implementation. Render...
authored
32
faa789a @Aijoona Added syntax highlight.
Aijoona authored
33 ```php
34 <?php
35 class Chris {
96596f4 @bobthecow Update README for 2.0-dev
authored
36 public $name = "Chris";
faa789a @Aijoona Added syntax highlight.
Aijoona authored
37 public $value = 10000;
38
39 public function taxed_value() {
40 return $this->value - ($this->value * 0.4);
b1c3e06 @bobthecow Added a second example. It's still not enough, but better than nothing.
authored
41 }
42
faa789a @Aijoona Added syntax highlight.
Aijoona authored
43 public $in_ca = true;
44 }
45 ```
fa8c81d @bobthecow Update README to reflect preferred mustache class implementation. Render...
authored
46
5363020 @bobthecow push some whitespace around a bit.
authored
47
faa789a @Aijoona Added syntax highlight.
Aijoona authored
48 And render it:
fa8c81d @bobthecow Update README to reflect preferred mustache class implementation. Render...
authored
49
faa789a @Aijoona Added syntax highlight.
Aijoona authored
50 ```php
51 <?php
be5cfb3 @bobthecow Rename Mustache_Mustache to Mustache_Engine.
authored
52 $m = new Mustache_Engine;
96596f4 @bobthecow Update README for 2.0-dev
authored
53 $chris = new Chris;
cb24d63 @bobthecow update README. simplify + link to wiki.
authored
54 echo $m->render($template, $chris);
faa789a @Aijoona Added syntax highlight.
Aijoona authored
55 ```
fa8c81d @bobthecow Update README to reflect preferred mustache class implementation. Render...
authored
56
57
6cd78e9 @bobthecow Usage.
authored
58 See Also
59 --------
60
cb24d63 @bobthecow update README. simplify + link to wiki.
authored
61 * [Mustache.php wiki](https://github.com/bobthecow/mustache.php/wiki/Home).
6cd78e9 @bobthecow Usage.
authored
62 * [Readme for the Ruby Mustache implementation](http://github.com/defunkt/mustache/blob/master/README.md).
cb24d63 @bobthecow update README. simplify + link to wiki.
authored
63 * [mustache(5)](http://mustache.github.com/mustache.5.html) man page.
Something went wrong with that request. Please try again.