-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathhelpers-2.php
More file actions
29 lines (25 loc) · 775 Bytes
/
Copy pathhelpers-2.php
File metadata and controls
29 lines (25 loc) · 775 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
<?php
$tmpl = <<<EOF
<ul>
{{#each items}}
<li>{{agree_button}}</li>
{{/each}}
</ul>
EOF;
$data = array(
'items' => array(
array('name' => 'Handlebars', 'emotion' => 'love'),
array('name' => 'Mustache', 'emotion' => 'enjoy'),
array('name' => 'Ember', 'emotion' => 'want to learn'),
),
);
$helpers = new Handlebars\DefaultRegistry();
$helpers['agree_button'] = function(Handlebars\Options $options) {
$emotion = htmlspecialchars($options->scope['emotion']);
$name = htmlspecialchars($options->scope['name']);
$result = "<button>I agree. I " . $emotion . " " . $name . "</button>";
return new Handlebars\SafeString($result);
};
$vm = new Handlebars\VM();
$vm->setHelpers($helpers);
echo $vm->render($tmpl, $data);