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

doesn't call helperMissing when using #with #264

Closed
joshrtay opened this issue Jun 28, 2012 · 3 comments
Closed

doesn't call helperMissing when using #with #264

joshrtay opened this issue Jun 28, 2012 · 3 comments
Labels

Comments

@joshrtay
Copy link

You would expect the following to call helperMissing:

Handlebars.compile("{{#with obj}}{{name}}{{/with}}")({});

but instead an error is thrown:

TypeError: Cannot read property 'name' of undefined
@wagenet
Copy link
Collaborator

wagenet commented Jun 28, 2012

I'm not sure that there's an easy answer to this. The {{name}} here is essentially being converted into {{obj.name}} which explains your error. Possibly we could have a try/catch statement that then tries helperMissing. I'm not sure if this is the right solution though.

@joshrtay
Copy link
Author

I understand why its throwing an error, but it seems like there should be a test to make sure obj exists before going forward.

something like this:

foundHelper = helpers.obj;
stack1 = foundHelper || depth0.obj;
if(stack1=== undefined) { stack1 = helpers['helperMissing'].call(depth0, "obj", { hash: {} }); }

this way helperMissing can return an obj if it needs to

@kpdecker
Copy link
Collaborator

kpdecker commented Apr 6, 2013

Calling helperMissing does not seem right here. 0872fb6 fixes the exception, causing no output from the with block if the object is undefined. If you need to have handling for the missing with case I would recommend adding an {{#unless obj}} block before or after your with call to output the content that you need for that case. i.e.

{{#with obj}}Its here!{{/with}}
{{#unless obj}}It's not{{/unless}}

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

3 participants