-
-
Notifications
You must be signed in to change notification settings - Fork 115
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
{{elsif}} or {{elseif}} or {{#elseif}} #39
Comments
Does handlebars have it? |
The issue is that this might seem a simple addition but would require a lot of changes internally. Like, a lot. |
Handlebars does not seem to have it. [Edit] To clarify, a preprocessor could simply use regexp (or some sort of parser) to replace the new syntax with the old one internally before it is processed. |
Hmmm. Maybe. So at the level or parser. Like a syntactic sugar. This could work. You could look into spacebars parser if you feel adventurous. :-) |
Got it :) -- will start digging into it. Is the parser part of this repo or somewhere else? |
totally agreed with this issue. Simple if/else if/else is just so usefull |
I've been wanting this every time I write an ugly if else if else chain, and today it caught my interest, so I've implemented a version using {{elseif}} (example taken from original post): {{#if condition1}}
{{elseif condition2}}
{{elseif condition3}}
{{/if}} As suggested, it is simply sugar syntax. The above example is transformed into the compiled spacebars version of this: {{#if condition1}}
{{else}}
{{#if condition2}}
{{else}}
{{#if condition3}}
{{/if}}
{{/if}}
{{/if}} |
Excellent @nathantreid, |
@ramezrafla Check out the PR link above my previous post. 😄 |
Oops - sorry - I'll blame it on small iPhone screen :) thanks a lot! |
When is this coming out? coming soon this summer 2017? |
@capensisma: Quoting Mitar (from my pull request):
|
Is there anything gating this? @mitar, want me to run some tests first? |
See the pull request #50. I would like that this is implemented compatible with Handlebars which allows any block helper to be used. So you can do:
Feel free to make a pull request like that. With tests and documentation. That would be great! |
Thanks @mitar, we can certainly adopt this syntax, but we can also add the other syntax above too. The two can be exclusive. Blaze has evolved quite a bit from Handlebars syntax. I personally like having elseif's -- it's more natural and less convoluted and would add value to developers. |
With 2fa3cab I implemented the Handlebars syntax for chaining block tags. After further consideration I did not implement |
Released as 2.3.0. You have to update templating package. |
@mitar and the rest, first of all, thanks a lot for keeping blaze alive. I'm writing here even if it's closed just to point one thing. Is it written anywhere which packages are needed to be updated? Again, thanks a lot! |
|
but meteor update also updates the meteor tool and so on. What if i just want to update blaze? |
Is this mentioned somewhere in the docs? I couldn't find anything. Thanks. |
It is documented here: http://blazejs.org/guide/spacebars.html#Chaining-of-Block-Helpers |
Thanks @mitar. I expected there to be a mention here: http://blazejs.org/guide/spacebars.html#If-Unless |
Feel free to make a pull request. :-) |
My blaze version is on 2.3.2. But I still cannot use |
Which version of |
My |
Then please create a small reproduction (a repo showcasing ony this issue). |
Error:
|
This is not a reproduction. Please create a small Meteor app in a git repo and provide a link to it here. Because the only thing I can tell you based on your snippet above is: it works for me. |
Oh, I figured out. It was caused by templating-compiler version. I was on @1.2.15. When I updated it to @1.3.2, it works. |
Can you please add this fix to the documentation of blaze |
I am suggesting we add an {{elsif}} or {{elseif}} or whatever variation to avoid this ugly piece of code:
Imagine this instead
I also think this will go a long way in making people more likely to adopt Blaze as it cleans up the code quite a bit for complex apps.
The text was updated successfully, but these errors were encountered: