You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 4563d15
Browse filesBrowse the repository at this point in the historyBrowse files
Removed the `helpers` compilation option. All helpers must now be passed at runtime when executing the template. This enables sharing helpers across multiple templates, and removes limitations on what helpers can access and do.
Also added `knownHelpers` option and updated `knownHelpersOnly` to work the same as in Handlebars.js.
Copy file name to clipboardExpand all lines: README.md
+27-22Lines changed: 27 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -62,14 +62,14 @@ echo $template(['first' => 'John']); // Error: Runtime: last does not exist
62
62
```
63
63
64
64
**Available Options:**
65
+
*`knownHelpers`: Associative array (`helperName => bool`) of helpers known to exist at template execution time. Passing this allows the compiler to optimize a number of cases. Builtin helpers are automatically included in this list.
65
66
*`knownHelpersOnly`: Enable to allow further optimizations based on the known helpers list.
66
67
*`noEscape`: Enable to not HTML escape any content.
67
68
*`strict`: Run in strict mode. In this mode, templates will throw rather than silently ignore missing fields.
68
69
*`assumeObjects`: Removes object existence checks when traversing paths. This is a subset of strict mode that generates optimized templates when the data inputs are known to be safe.
69
70
*`preventIndent`: Prevent indented partial-call from indenting the entire partial output by the same amount.
70
71
*`ignoreStandalone`: Disables standalone tag removal. When set, blocks and partials that are on their own line will not remove the whitespace on that line.
71
72
*`explicitPartialContext`: Disables implicit context for partials. When enabled, partials that are not passed a context value will execute against an empty object.
72
-
*`helpers`: Provide a key => value array of custom helper functions.
73
73
*`partials`: Provide a key => value array of custom partial templates.
74
74
*`partialResolver`: A closure which will be called for any partial not in the `partials` array to return a template for it.
75
75
@@ -83,28 +83,30 @@ This object contains properties for accessing `hash` arguments, `data`, and the
83
83
For example, a custom `#equals` helper with JS equality semantics could be implemented as follows:
84
84
85
85
```php
86
-
use DevTheorem\Handlebars\{Handlebars, HelperOptions, Options};
86
+
use DevTheorem\Handlebars\{Handlebars, HelperOptions};
87
87
88
-
$template = Handlebars::compile('{{#equals my_var false}}Equal to false{{else}}Not equal{{/equals}}', new Options(
89
-
helpers: [
88
+
$template = Handlebars::compile('{{#equals my_var false}}Equal to false{{else}}Not equal{{/equals}}');
89
+
$options = [
90
+
'helpers' => [
90
91
'equals' => function (mixed $a, mixed $b, HelperOptions $options) {
91
92
$jsEquals = function (mixed $a, mixed $b): bool {
92
-
if ($a === null || $b === null) {
93
-
// in JS, null is not equal to blank string or false or zero
@@ -150,7 +152,10 @@ Helpers may return a `DevTheorem\Handlebars\SafeString` instance to prevent esca
150
152
When constructing the string that will be marked as safe, any external content should be properly escaped
151
153
using the `Handlebars::escapeExpression()` method to avoid potential security concerns.
152
154
153
-
## Missing features
155
+
## Missing Features
156
+
157
+
All syntax and language features from Handlebars.js 4.7.8 should work the same in PHP Handlebars,
158
+
with the following exceptions:
154
159
155
-
All syntax from Handlebars.js 4.7.8 should work the same in this implementation, with the following exception:
156
-
*Decorators ([deprecated in Handlebars.js](https://github.com/handlebars-lang/handlebars.js/blob/master/docs/decorators-api.md)) have not been implemented.
160
+
* Custom Decorators have not been implemented, as they are [deprecated in Handlebars.js](https://github.com/handlebars-lang/handlebars.js/blob/master/docs/decorators-api.md).
161
+
*The `data` and `compat` compilation options have not been implemented.
0 commit comments