-
Notifications
You must be signed in to change notification settings - Fork 397
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
handlebars mode cannot handle {{#foo}} and {{#if foo}} in the same template, and can't handle {{^foo}} at all #770
Comments
To avoid bug spam: handlebars mode can't handle |
I don't think this is an issue with Ractive. Ractive, by default, uses Mustache as its templating system, and Mustache uses |
API-wise, I'm not sure one way or the other whether this should work. I'm inclined to say the mustache-based directives should continue to work. @marcello3d (or maybe @jrajav): Is there any technical reason in the parser can't continue to process mustache-based directives when |
@joshuasmock Handlebars is not an "independent system." It is Mustache, with all of the usual Mustache sections, plus a bunch of other stuff like block sections. If Ractive can't mix Mustache style sections and Handlebars style sections, then Ractive doesn't conform with the official Handlebars compiler. @martypdx If it is undesirable to allow "mixing", we should document that difference. |
There's no technical limitation. Handlebars is described as a super-set of mustache, so it should probably be allowed. On the other handle, we already cannot claim to support any existing mustache/handlebars template, since you're restricted to a DOM tree structure. My personal feeling is that it is a flaw in handlebars' design to allow mixing of mustache and handlebars-style control blocks because it's a potential source of errors. I'd be all for relegating the restriction to a "strict" mode. |
I think separating Handlebars mode from strict mode, and allowing mixed styles in non-strict mode, is a good call. IIRC that shouldn't be tricky to implement, we're most of the way there already. How does everyone feel about enabling Handlebars mode by default, and making strict mode optional? (Or making strict mode the default...? Though that would be a source of breaking changes and confusion for some users who are currently doing things like |
Unless you want to do a lot of marketing around the change, I'd be hesitant to switch to a handlebars-only strict mode. I think something like this is better to do gradually. If you feel that the handlebars syntax is better and want to migrate Ractive, I would do the following:
That might be enough. |
@monsanto: Since @marcello3d said that Handlebars is described as a super set of Mustache, do both flavors work in conjunction with one another in pure handlebars.js? In other words, will a template with both Like @marcello3d says above, I'd also be hesitant to change template systems completely without a deprecation warning in place, but I also think that supporting both styles simultaneously could cause errors to creep in unexpectedly as well as confusion; I favor being strict in the implementations of both Mustache and Handlebars since Ractive's goal isn't to be a templating engine. However, an interesting idea could be to develop a way to test for and determine the template style, and use that engine without having to declare it. For example, if I have both a Handlebars and a Mustache template, both could work without having to declare which is which because Ractive would know. |
@marcello3d I think for #2, documentation should show both where it makes sense. Seems like could use a single option like |
@martypdx good idea |
@martypdx to avoid confusion, what about the following 3 modes:
Though, unless there's a strong desire for a mustache-only mode, I'd keep it simple and only support 2 & 3. |
@joshuasmock
Yes, as I said in the first post I can confirm that this is supposed to work, and pointed to tryhandlebarsjs.com (which is using the latest release of Handlebars) so you can see for yourself To be clear, I don't really care if you can mix the two. It would have been handy when porting from Mustache -> Handlebars, because I wouldn't have had to do it all at once, but for newer users I think we should just recommend using Handlebars from the start. |
@monsanto Oh, wow, sorry! I completely missed that. @Rich-Harris I would say that since handlebars.js accepts Mustache templates by default, then I think two modes would be best:
I would guess that since Ractive produces these errors where handlebars.js doesn't, then Ractive doesn't use handlebars.js. Would it be possible to port or drop-in handlebars.js for use within Ractive, barring size concerns? |
I don't think Ractive should be preferential towards handlebars. We don't really support handlebars, we just borrowed some handy mustache syntax extensions. What if we treat this issue as a bug, fix the parser to handle both, and do this release without an option? Then we see how people use it, what comments and issues we see, then make adjustments in future release.
@joshuasmock handlebars compiles to javascript functions that return a string, so they wouldn't be useful for two-way binding. |
I'd be in favour of that. Only remaining question then would be what |
I missed that one, it never made it into up into the declared ractive options. :) Looking at the code, it's only used here to figure out the closing tag: if ( parser.options.strict || parser.handlebars ) {
switch ( mustache.n ) {
case types.SECTION_IF:
expectedClose = 'if';
break;
... It seems to me that we could just enforce this if one of the handlebars extensions is used to open the tag. Then we don't need that option either. But @marcello3d should chime in. |
|
Enforcing closing tag catches bugs earlier and makes templates more readable, so I think we should continue requiring it for the handlebars-if/with/unless/each blocks. As for strict mode/mismatched mustache-style blocks, it's not always clear what the appropriate close string should be, so I say hold off. (Perhaps strict mode will mean eliminating mustache-style blocks entirely—but I don't think we're ready to make that call.) |
Right, so we always check for if/with/unless/each, meaning we don't need strict mode for now. |
I don't think that a strict mode would be necessary if the major differences are the extended template syntax that Handlebars provides on top of Mustache, in this case the addition of |
@joshuasmock I was actually suggesting strict mode would prevent mustache blocks without an explicit handlebars-style if/unless/each/with |
@marcello3d Oh. But doesn't Handlebars parse |
@joshuasmock Yes, but I think it's a bad design. |
Handlebars-style blocks are now always supported: http://jsfiddle.net/rich_harris/DQa4p/ There's no |
http://jsfiddle.net/ezLqe/35/
check console for parse error. can confirm it is supposed to work in tryhandlebarsjs.com
The text was updated successfully, but these errors were encountered: