Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 63 lines (43 sloc) 1.161 kB
6cd78e9 @bobthecow Usage.
authored
1 Mustache.php
2 ============
3
0e73e66 @bobthecow Updating readme to link to pretty Mustache homepage rather than githu…
authored
4 A [Mustache](http://defunkt.github.com/mustache/) implementation in PHP.
6cd78e9 @bobthecow Usage.
authored
5
6
7 Usage
8 -----
9
10 A quick example:
11
faa789a @Aijoona Added syntax highlight.
Aijoona authored
12 ```php
13 <?php
14 $m = new Mustache;
cb24d63 @bobthecow update README. simplify + link to wiki.
authored
15 echo $m->render('Hello {{planet}}', array('planet' => 'World!')); // "Hello World!"
faa789a @Aijoona Added syntax highlight.
Aijoona authored
16 ```
6cd78e9 @bobthecow Usage.
authored
17
18
96596f4 @bobthecow Update README for 2.0-dev
authored
19 And a more in-depth example -- this is the canonical Mustache template:
6cd78e9 @bobthecow Usage.
authored
20
faa789a @Aijoona Added syntax highlight.
Aijoona authored
21 ```
22 Hello {{name}}
23 You have just won ${{value}}!
24 {{#in_ca}}
25 Well, ${{taxed_value}}, after taxes.
26 {{/in_ca}}
27 ```
6cd78e9 @bobthecow Usage.
authored
28
5363020 @bobthecow push some whitespace around a bit.
authored
29
96596f4 @bobthecow Update README for 2.0-dev
authored
30 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. Ren…
authored
31
faa789a @Aijoona Added syntax highlight.
Aijoona authored
32 ```php
33 <?php
34 class Chris {
96596f4 @bobthecow Update README for 2.0-dev
authored
35 public $name = "Chris";
faa789a @Aijoona Added syntax highlight.
Aijoona authored
36 public $value = 10000;
37
38 public function taxed_value() {
39 return $this->value - ($this->value * 0.4);
b1c3e06 @bobthecow Added a second example. It's still not enough, but better than nothing.
authored
40 }
41
faa789a @Aijoona Added syntax highlight.
Aijoona authored
42 public $in_ca = true;
43 }
44 ```
fa8c81d @bobthecow Update README to reflect preferred mustache class implementation. Ren…
authored
45
5363020 @bobthecow push some whitespace around a bit.
authored
46
faa789a @Aijoona Added syntax highlight.
Aijoona authored
47 And render it:
fa8c81d @bobthecow Update README to reflect preferred mustache class implementation. Ren…
authored
48
faa789a @Aijoona Added syntax highlight.
Aijoona authored
49 ```php
50 <?php
51 $m = new Mustache;
96596f4 @bobthecow Update README for 2.0-dev
authored
52 $chris = new Chris;
cb24d63 @bobthecow update README. simplify + link to wiki.
authored
53 echo $m->render($template, $chris);
faa789a @Aijoona Added syntax highlight.
Aijoona authored
54 ```
fa8c81d @bobthecow Update README to reflect preferred mustache class implementation. Ren…
authored
55
56
6cd78e9 @bobthecow Usage.
authored
57 See Also
58 --------
59
cb24d63 @bobthecow update README. simplify + link to wiki.
authored
60 * [Mustache.php wiki](https://github.com/bobthecow/mustache.php/wiki/Home).
6cd78e9 @bobthecow Usage.
authored
61 * [Readme for the Ruby Mustache implementation](http://github.com/defunkt/mustache/blob/master/README.md).
cb24d63 @bobthecow update README. simplify + link to wiki.
authored
62 * [mustache(5)](http://mustache.github.com/mustache.5.html) man page.
Something went wrong with that request. Please try again.