Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- **Named Filter Arguments** (#42): Added keyword arguments for filters, including `allow_false` support in the `default` filter.
- **String Literal Escapes** (#45): Added `\\`, `\"`, `\n`, `\t`, and `\r` escapes in double-quoted string literals. Single-quoted strings remain literal.
- **Shopify Filters** (#146): Added `where`, `sum`, `at_least`, `at_most`, `pluralize`, `handleize`/`handle`, `remove_last`, and `replace_last`.
- **Render Tag** (#128, #129): Added isolated snippet rendering with named parameters and `with`, `for`, and `as` forms.

### Fixed

Expand Down
19 changes: 15 additions & 4 deletions render/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,21 @@ func (c rendererContext) RenderChildren(w io.Writer) Error {
}

func (c rendererContext) RenderFile(filename string, b map[string]any) (string, error) {
bindings := make(map[string]any, len(c.ctx.bindings)+len(b))
maps.Copy(bindings, c.ctx.bindings)
maps.Copy(bindings, b)

return c.renderFile(filename, bindings)
}

// RenderFileIsolated renders a template without inheriting the parent lexical scope.
// It is intentionally not part of Context, so adding the render tag does not break
// third-party Context implementations.
func (c rendererContext) RenderFileIsolated(filename string, bindings map[string]any) (string, error) {
return c.renderFile(filename, maps.Clone(bindings))
}

func (c rendererContext) renderFile(filename string, bindings map[string]any) (string, error) {
source, err := c.ctx.config.TemplateStore.ReadTemplate(filename)
if err != nil && errors.Is(err, fs.ErrNotExist) {
// Is it cached?
Expand All @@ -177,10 +192,6 @@ func (c rendererContext) RenderFile(filename string, b map[string]any) (string,
return "", err
}

bindings := make(map[string]any, len(c.ctx.bindings)+len(b))
maps.Copy(bindings, c.ctx.bindings)
maps.Copy(bindings, b)

buf := new(bytes.Buffer)
if err := Render(root, buf, bindings, c.ctx.config); err != nil {
return "", err
Expand Down
Loading
Loading