Skip to content

Basic support for the "with" template helper#28

Merged
vincent-psarga merged 2 commits intoSmartBear:masterfrom
creature:add-with-support
Jan 11, 2021
Merged

Basic support for the "with" template helper#28
vincent-psarga merged 2 commits intoSmartBear:masterfrom
creature:add-with-support

Conversation

@creature
Copy link
Contributor

One of Handlebars' built-in helpers is {{with}}, which allows you to change "contexts" in a template. Basically, it makes it easier to use nested objects. As the Handlebars documentation demonstrates, given this data:

{ person: { firstname: "Yehuda", lastname: "Katz" } }

Then you can write this template to render "Yehuda Katz":

{{#with person}}
{{firstname}} {{lastname}}
{{/with}}

This PR adds basic support for this helper, along with some test cases (taken from the Handlebars documentation) to demonstrate it works.


One wrinkle with this PR: it doesn't support relative paths, as that's not yet supported in ruby-handlebars. I've included a (skipped) test case that demonstrates this (which works in the Handlebars playground), but I can't figure out how to add parser support for that. Some help here would be very welcome! I'd also like to add support for {{lookup}}, but getting relative paths to work is a prerequisite for that.

@vincent-psarga vincent-psarga merged commit e730124 into SmartBear:master Jan 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants