Skip to content

Commit 7dc199e

Browse files
committed
Temp todos
1 parent 53db6df commit 7dc199e

2 files changed

Lines changed: 103 additions & 0 deletions

File tree

test.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
use DevTheorem\Handlebars\Handlebars;
4+
5+
require 'vendor/autoload.php';
6+
7+
$templateStr = <<<'HBS'
8+
{{#each (json jsonStr)}}
9+
{{@key}}: {{.}}
10+
{{/each}}
11+
HBS;
12+
13+
$helpers = [
14+
'json' => fn(string $json) => json_decode($json, true),
15+
];
16+
17+
$template = Handlebars::compile($templateStr);
18+
19+
$data = [
20+
'jsonStr' => '{"foo":"bar"}',
21+
];
22+
echo $template($data, ['helpers' => $helpers]);

todo.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
Double-check every LightnCandy issue where I left a comment, to see if any need to be updated following the helpers changes.
2+
3+
- [x] https://github.com/zordius/lightncandy/issues/371
4+
- [x] https://github.com/zordius/lightncandy/issues/360
5+
- [x] https://github.com/zordius/lightncandy/issues/356
6+
- [x] https://github.com/zordius/lightncandy/issues/350
7+
- [x] https://github.com/zordius/lightncandy/issues/347
8+
- [x] https://github.com/zordius/lightncandy/issues/346
9+
- [x] https://github.com/zordius/lightncandy/issues/345
10+
- [x] https://github.com/zordius/lightncandy/issues/341
11+
- [x] https://github.com/zordius/lightncandy/issues/318
12+
- [x] https://github.com/zordius/lightncandy/issues/299
13+
- [x] https://github.com/zordius/lightncandy/issues/297
14+
- [ ] https://github.com/zordius/lightncandy/issues/296 - comment with example of dynamically loading in PHP Handlebars 1.1.
15+
- [x] https://github.com/zordius/lightncandy/issues/294
16+
- [x] https://github.com/zordius/lightncandy/issues/293
17+
- [ ] https://github.com/zordius/lightncandy/issues/292 - Comment with fixed after releasing v1.1.0 (see below)
18+
- [ ] https://github.com/zordius/lightncandy/issues/268 - maybe add comment with PHP Handlebars demo
19+
- [ ] https://github.com/zordius/lightncandy/issues/266 - investigate later
20+
- [ ] https://github.com/zordius/lightncandy/issues/242 - comment that simpler in PHP Handlebars
21+
- [ ] https://github.com/zordius/lightncandy/issues/228 - Comment with note about first-class callable syntax
22+
23+
- [ ] https://github.com/devtheorem/php-handlebars/issues/5 mention in commit when resolving (along with https://github.com/zordius/lightncandy/issues/296), comment after v1.1 release
24+
25+
For issue 292:
26+
27+
Nested partials are fully supported, both at compile and render time in [PHP Handlebars](https://github.com/devtheorem/php-handlebars):
28+
29+
```php
30+
use DevTheorem\Handlebars\{Handlebars, Options};
31+
32+
require 'vendor/autoload.php';
33+
34+
$templateString = '{{#>outer}} {{#>compiledBlock}} real inner compiledBlock {{/compiledBlock}} {{>normalTemplate}} {{/outer}}';
35+
36+
$template = Handlebars::compile($templateString, new Options(
37+
partials: [
38+
'outer' => 'outer+{{#>nested}}~{{>@partial-block}}~{{/nested}}+outer-end',
39+
'nested' => 'nested={{>@partial-block}}=nested-end',
40+
],
41+
));
42+
43+
echo $template(null, [
44+
'partials' => [
45+
'compiledBlock' => Handlebars::compile('compiledBlock !!! {{>@partial-block}} !!! compiledBlock'),
46+
'normalTemplate' => Handlebars::compile('normalTemplate'),
47+
],
48+
]);
49+
```
50+
51+
Output (matching Handlebars.js):
52+
> outer+nested=~ compiledBlock !!! real inner compiledBlock !!! compiledBlock normalTemplate ~=nested-end+outer-end
53+
54+
The second example also works correctly in PHP Handlebars, with both compile-time and runtime partials:
55+
56+
```php
57+
use DevTheorem\Handlebars\{Handlebars, Options};
58+
59+
require 'vendor/autoload.php';
60+
61+
$templateString = '{ {{#>outer}} {{#>innerBlock}} Hello {{/innerBlock}} {{>simple}} {{/outer}} }';
62+
63+
$partials = [
64+
'outer' => '( {{#>nested}} « {{>@partial-block}} » {{/nested}} )',
65+
'nested' => '[ {{>@partial-block}} ]',
66+
'innerBlock' => '< {{>@partial-block}} >',
67+
'simple' => 'World!',
68+
];
69+
70+
$templateWithPartials = Handlebars::compile($templateString, new Options(partials: $partials));
71+
echo $templateWithPartials() . " (compile time)\n";
72+
73+
$templateWithoutPartials = Handlebars::compile($templateString);
74+
$compiledPartials = array_map(fn($p) => Handlebars::compile($p), $partials);
75+
76+
echo $templateWithPartials(null, ['partials' => $compiledPartials]) . " (runtime)\n";
77+
```
78+
79+
Output:
80+
> { ( [ « < Hello > World! » ] ) } (compile time)
81+
> { ( [ « < Hello > World! » ] ) } (runtime)

0 commit comments

Comments
 (0)