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

IncludeHelper #217

Closed
tomvanrossom opened this issue Aug 1, 2013 · 3 comments
Closed

IncludeHelper #217

tomvanrossom opened this issue Aug 1, 2013 · 3 comments
Labels
Milestone

Comments

@tomvanrossom
Copy link

I'm trying to use the includeHelper, but I'm having some troubles.

In my templates I've got something like this:

{{include "templateName" includeContext=modelAttribute}}

and in the template "templateName" I'm trying:

{{includeContext}}
{{#includeContext.property1}}
   {{property2}}
{{/includeContext.property1}}

The "{{includeContext}}" prints out something, the "{{property2}}" not (although there is data in it)!

When I debug the code I see that the IncludeHelper copies the hashes to the context.data

public CharSequence apply(final String partial, final Options options) throws IOException {
    // merge all the hashes into the context
    options.context.data(options.hash);
...

But when the actual data is retrieved in the class "Block"

protected void merge(final Context context, final Writer writer) throws IOException {
    ...
    if (helper == null) {
      childContext = transform(context.get(name));
      ...

The following method of Context is eventually called:

private Object get(final String[] path) {
    Object current = model;

This method used the 'model' instead of the 'data'. I find this strange, because the IncludeHelper copied the hashes to the data, and not the model!??!

What am I doing wrong? Or is this an issue?

@tomvanrossom
Copy link
Author

I've found a work-arround by not using the 'include' which is compatible in handlebars.js and hanldebars.java

instead of using

{{include "templateName" includeContext=modelAttribute}}

I'm using the 'with' blockhelper for setting the context:

{{#with modelAttribute}}
    {{> templateName this}}
{{/with}}

This works fine (in .js and .java!), but does not solve the issue with the include-helper

@jknack
Copy link
Owner

jknack commented Aug 1, 2013

The include helper is a community donation, see #140

It was added bc in handlebars.js partials with context wasn't supported. Anyway, will check if handlebars.js can or can't have a custom context and update/remove the include helper if necessary.

In the mean while, just use plain partials bc in handlebars.java they work as the Mustache Spec said.

@tomvanrossom
Copy link
Author

I did not encounter an issue with the include helper of handlebars.js only with the helper of handlebars.java

Thanks for the response!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants