Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic support for the "with" template helper #28

Merged
merged 2 commits into from
Jan 11, 2021

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