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
| LightnCandy 1.2.6 | 5.2 ms | 2.8 ms | 8.0 ms | 5.3 MB |
13
-
| PHP Handlebars 1.0| 3.5 ms | 1.6 ms | 5.1 ms | 3.6 MB |
13
+
| PHP Handlebars 1.1| 3.5 ms | 1.6 ms | 5.1 ms | 3.6 MB |
14
14
15
15
_Tested on PHP 8.5 with the JIT enabled. See the `benchmark` branch to run the same test._
16
16
@@ -72,39 +72,37 @@ echo $template(['first' => 'John']); // Error: "last" not defined
72
72
73
73
*`knownHelpers`: Associative array (`helperName => bool`) of helpers known to exist at template execution time.
74
74
Passing this allows the compiler to optimize a number of cases.
75
-
Builtin helpers are automatically included in this list and may be omitted by setting that value to `false`.
76
-
*`knownHelpersOnly`: Enable to allow further optimizations based on the known helpers list.
77
-
*`noEscape`: Enable to not HTML escape any content.
75
+
Built-in helpers are automatically included in this list and may be omitted by setting that value to `false`.
76
+
*`knownHelpersOnly`: Set to `true` to allow further optimizations based on the known helpers list.
77
+
*`noEscape`: Set to `true` to disable HTML escaping of output.
78
78
*`strict`: Run in strict mode. In this mode, templates will throw rather than silently ignore missing fields.
79
79
This has the side effect of disabling inverse operations such as `{{^foo}}{{/foo}}`
80
80
unless fields are explicitly included in the source object.
81
81
*`assumeObjects`: Removes object existence checks when traversing paths.
82
82
This is a subset of strict mode that generates optimized templates when the data inputs are known to be safe.
83
-
*`preventIndent`: Prevent indented partial-call from indenting the entire partial output by the same amount.
83
+
*`preventIndent`: Prevents an indented partialcall from indenting the entire partial output by the same amount.
84
84
*`ignoreStandalone`: Disables standalone tag removal.
85
85
When set, blocks and partials that are on their own line will not remove the whitespace on that line.
86
86
*`explicitPartialContext`: Disables implicit context for partials.
87
87
When enabled, partials that are not passed a context value will execute against an empty object.
88
-
*`partials`: Provide a `name => value` array of custom partial template strings.
89
-
*`partialResolver`: A closure which will be called for any partial not in the `partials` array to return a template for it.
88
+
*`partials`: An associative array of custom partial template strings (`name => template`).
89
+
*`partialResolver`: A closure that will be called for any partial not found in the `partials` array,
90
+
and should return a template string for it.
90
91
91
92
## Runtime Options
92
93
93
94
`Handlebars::compile` returns a closure which can be invoked as `$template($context, $options)`.
94
95
The `$options` parameter takes an array of runtime options, accepting the following keys:
95
96
96
-
*`data`: An array to define custom `@variable` private variables.
97
-
*`helpers`: An `array<string, \Closure>` containing custom helpers to add to the built-in helpers.
98
-
*`partials`: An `array<string, \Closure>` containing partial functions precompiled with `Handlebars::compile`.
99
-
This is useful if multiple templates sharing the same partials need to be compiled and rendered, and you don't want
100
-
to recompile the same partials over and over for each template.
97
+
*`data`: An associative array of initial `@data` variables (e.g. `['version' => '1.0']` makes `@version` available in the template).
98
+
*`helpers`: An `array<string, \Closure>` of helpers to merge with the built-in helpers. Can also be used to override a built-in helper by using the same name.
99
+
*`partials`: An `array<string, \Closure>` of partial closures precompiled with `Handlebars::compile`.
100
+
Useful when multiple templates share the same partials, and you want to avoid recompiling them for each template.
101
101
102
102
## Custom Helpers
103
103
104
104
Helper functions will be passed any arguments provided to the helper in the template.
105
105
If needed, a final `$options` parameter can be included which will be passed a `HelperOptions` instance.
106
-
This object contains properties for accessing `hash` arguments, `data`, and the current `scope`, `name`,
107
-
as well as `fn()` and `inverse()` methods to render the block and else contents, respectively.
108
106
109
107
For example, a custom `#equals` helper with JS equality semantics could be implemented as follows:
0 commit comments