-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathhelpers.php
More file actions
35 lines (29 loc) · 794 Bytes
/
Copy pathhelpers.php
File metadata and controls
35 lines (29 loc) · 794 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
$tmpl = <<<EOF
<div class="post">
<h1>By {{fullName author}}</h1>
<div class="body">{{body}}</div>
<h1>Comments</h1>
{{#each comments}}
<h2>By {{fullName author}}</h2>
<div class="body">{{body}}</div>
{{/each}}
</div>
EOF;
$data = array(
'author' => array('firstName' => 'Alan', 'lastName' => 'Johnson'),
'body' => 'I Love Handlebars',
'comments' => array(
array(
'author' => array('firstName' => 'Yehuda', 'lastName' => 'Katz'),
'body' => 'Me too!',
),
),
);
$helpers = new Handlebars\DefaultRegistry();
$helpers['fullName'] = function($person) {
return $person['firstName'] . ' ' . $person['lastName'];
};
$vm = new Handlebars\VM();
$vm->setHelpers($helpers);
echo $vm->render($tmpl, $data);