Skip to content

Commit f2ec6e5

Browse files
committed
Release 1.2.0
1 parent 2a17c2b commit f2ec6e5

2 files changed

Lines changed: 32 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,27 @@ All notable changes to this project will be documented in this file.
33

44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
55

6+
## [1.2.0] Data Frames - 2026-03-30
7+
8+
### Added
9+
- `Handlebars::createFrame()`: creates a child `@data` frame inheriting fields from a parent frame,
10+
equivalent to `Handlebars.createFrame()` in Handlebars.js.
11+
12+
### Changed
13+
- To align with Handlebars.js, `@data` variables passed to `fn()` or `inverse()` by block helpers are
14+
no longer automatically merged with parent data and `@root`. For example, if a helper calls `fn()`
15+
with `['data' => ['index' => 0]]` as the second parameter, `@index` will now be the *only* `@data`
16+
variable inside the block. To set `@`-prefixed variables while still inheriting parent `@data`
17+
variables, call `Handlebars::createFrame($options->data)` to create an isolated child frame.
18+
Then assign new keys to it before passing it to the `data` option of `fn()` or `inverse()`.
19+
- `Handlebars::escapeExpression()` now uses `strtr()` instead of `str_replace()` for better performance.
20+
21+
### Fixed
22+
- Block param path lookups and literal path lookups (e.g. `{{"foo"}}`, `{{#"foo"}}`) in `strict`
23+
mode no longer incorrectly throw when the key exists but its value is `null`.
24+
- Inline partials defined inside an `{{else}}` block no longer leak into the surrounding scope.
25+
26+
627
## [1.1.0] Dynamic Partial Resolution - 2026-03-26
728

829
### Added
@@ -182,6 +203,7 @@ Initial release after forking from LightnCandy 1.2.6.
182203
- HTML documentation.
183204
- Dozens of unnecessary feature flags.
184205

206+
[1.2.0]: https://github.com/devtheorem/php-handlebars/compare/v1.1.0...v1.2.0
185207
[1.1.0]: https://github.com/devtheorem/php-handlebars/compare/v1.0.1...v1.1.0
186208
[1.0.1]: https://github.com/devtheorem/php-handlebars/compare/v1.0.0...v1.0.1
187209
[1.0.0]: https://github.com/devtheorem/php-handlebars/compare/v0.9.9...v1.0.0

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,9 @@ echo $template(['my_var' => null], $runtimeOptions); // Not equal
154154
(e.g. `{{#helper as |a b|}}` produces `2`).
155155

156156
* `scope` (`mixed`): The current evaluation context (equivalent to `this` in a Handlebars.js helper).
157-
Can be reassigned inside a helper to change the context passed to `fn()`.
158157

159-
* `data` (`array`): The current `@data` frame. Contains `@`-prefixed private variables such as
160-
`root`, `index`, `key`, `first`, `last`, and `_parent`. Can be read or modified inside a helper.
158+
* `data` (`array`): The current `@data` frame. `root` refers to the top-level context.
159+
`index`, `key`, `first`, and `last` are set by `{{#each}}` blocks. Can be read or modified inside a helper.
161160

162161
### HelperOptions Methods
163162

@@ -177,7 +176,7 @@ echo $template(['my_var' => null], $runtimeOptions); // Not equal
177176
remainder of the render. The closure must be produced by `Handlebars::compile`.
178177

179178
> [!NOTE]
180-
> `isset($options->fn)` and `isset($options->inverse)` return true if the helper was called as a block,
179+
> `isset($options->fn)` and `isset($options->inverse)` return `true` if the helper was called as a block,
181180
> and `false` for inline helper calls.
182181
183182
## Hooks
@@ -222,6 +221,13 @@ Helpers may return a `DevTheorem\Handlebars\SafeString` instance to prevent esca
222221
When constructing the string that will be marked as safe, any external content should be properly escaped
223222
using the `Handlebars::escapeExpression()` method to avoid potential security concerns.
224223

224+
## Data Frames
225+
226+
Block helpers that inject `@`-prefixed variables should create a child data frame using
227+
`Handlebars::createFrame($options->data)`, add their variables to it, and pass it to `fn()` or `inverse()`
228+
via the `data` key (e.g. `$options->fn($context, ['data' => $frame])`). This mirrors `Handlebars.createFrame()`
229+
in Handlebars.js, isolating the helper's variables while still inheriting parent data such as `@root`.
230+
225231
## Missing Features
226232

227233
All syntax and language features from Handlebars.js 4.7.9 should work the same in PHP Handlebars,

0 commit comments

Comments
 (0)