Skip to content

Commit bbca7fe

Browse files
committed
Temp todos
1 parent b7127eb commit bbca7fe

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed

test.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
use DevTheorem\Handlebars\{Handlebars, HelperOptions};
4+
5+
require 'vendor/autoload.php';
6+
7+
$templateStr = <<<VAREND
8+
{{test "foo" prop="\" "}}
9+
VAREND;
10+
11+
$helpers = [
12+
'test' => function ($viewName, HelperOptions $options) {
13+
return $options->hash['prop'];
14+
},
15+
];
16+
17+
$template = Handlebars::compile($templateStr);
18+
19+
echo $template(null, ['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+
- [ ] https://github.com/zordius/lightncandy/issues/312 - maybe comment with PHP Handlebars example?
13+
- [ ] https://github.com/zordius/lightncandy/issues/299 - Comment with PHP Handlebars example.
14+
- [x] https://github.com/zordius/lightncandy/issues/297
15+
- [ ] https://github.com/zordius/lightncandy/issues/296 - comment with example of dynamically loading in PHP Handlebars 1.1.
16+
- [ ] https://github.com/zordius/lightncandy/issues/294
17+
- [ ] https://github.com/zordius/lightncandy/issues/293
18+
- [ ] https://github.com/zordius/lightncandy/issues/292 - Comment with fixed after releasing v1.1.0 (see below)
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)