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

HTML comments in handlebars templates cause error. #1580

Closed
nullrocket opened this issue Dec 7, 2012 · 7 comments
Closed

HTML comments in handlebars templates cause error. #1580

nullrocket opened this issue Dec 7, 2012 · 7 comments

Comments

@nullrocket
Copy link

I had temporarily commented out some html in a template. The commented out code contained a couple {{variables}} like this.

<!-- <div>{{variable}} </div> -->

This causes the error *Cannot perform operations on a Metamorph that is not in the DOM. * this error happens when the view is disconnected from an outlet.

Not sure what the fix should be. I often comment out html while in development so I would say that it needs to be handled.

Version: v1.0.0-pre.2

@sly7-7
Copy link
Contributor

sly7-7 commented Dec 7, 2012

I'm not 100% sure, but I think I've seen handlebars line comments, using {{! }}, could try it and tell if it works ? These are line comments in handlebars see: http://handlebarsjs.com/

@nullrocket
Copy link
Author

Yes those work, no problem there. Its the case I noted, which isn't mentioned anywhere that I can find:

<!-- <div>{{variable}} </div> -->

There is no documentation on that being a problem, and html comments are allowed in handlebars templates, so perhaps the fix is as easy as documenting that it will cause an error to be thrown if there are {{}} with it.

@wagenet
Copy link
Member

wagenet commented Dec 7, 2012

@phpaddiction The issue is that Handlebars is not aware of its surrounding code. It doesn't know that it's inside of a comment so it sets up the binding infrastructure. The master version of Handlebars has support for block comments which long term are the best solution. You use them as such: {{!-- <div>{{variable}}</div> --}}. This will prevent any Handlebars blocks inside from being interpreted. If you'd like to add a comment about this issue to the docs, we'd be happy to have a PR.

@wagenet wagenet closed this as completed Dec 7, 2012
@nullrocket
Copy link
Author

Sounds like a comment for both emberjs and handlebars docs would be good enough. It was a couple hour time sink to figure out :). Perhaps a little more info in the debug version exception about this being a possible cause of the error *Cannot perform operations on a Metamorph that is not in the DOM. *

This is what is on the handlebars site, nothing to lead me to think that it would be an issue.

The comments will not being in the resulting output. If you'd like the comments to show up. Just use html comments, > and they will be output.

{{! This comment will not be in the output }}

Anyway, thanks for taking a look at this.

@wagenet
Copy link
Member

wagenet commented Dec 7, 2012

@phpaddiction The Metamorph issue is specific to Ember. However, the blocks in HTML comments will still be processed in standard Handlebars unless they are wrapped in a block Handlebars comment.

@nullrocket
Copy link
Author

Makes sense, I haven't used handlebars outside Ember so I wasn't sure. I'm just happy there is a reason and I can avoid it now.

@wagenet
Copy link
Member

wagenet commented Dec 7, 2012

Yeah, sorry for the trouble. Ideally we'd get a more useful error message. I'll see what we can do about it.

makepanic added a commit to makepanic/globe that referenced this issue Apr 13, 2014
fixed bug: emberjs/ember.js#1580
fixed bug: it could happen that the graph renderer tries to render without data
fixed bug: it could happen that computing 3_days throws an error because a bridge has periods for 3_months, 1_year but not 1_week
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

No branches or pull requests

3 participants