Comments (33)
Released as 2.3.0. You have to update templating package.
from blaze.
Does handlebars have it?
from blaze.
The issue is that this might seem a simple addition but would require a lot of changes internally. Like, a lot.
from blaze.
Handlebars does not seem to have it.
I was thinking .. a preprocessor would do the trick :)
[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.
Also, this preprocessor can allow future improvements without touching the code. Given it only runs once per template, the overhead is negligible.
from blaze.
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. :-)
from blaze.
Got it :) -- will start digging into it. Is the parser part of this repo or somewhere else?
from blaze.
https://github.com/meteor/blaze/tree/master/packages/spacebars-compiler
from blaze.
totally agreed with this issue. Simple if/else if/else is just so usefull
from blaze.
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):
As suggested, it is simply sugar syntax. The above example is transformed into the compiled spacebars version of this:
from blaze.
Excellent @nathantreid,
Can you PR with your changes?
from blaze.
@ramezrafla Check out the PR link above my previous post. 😄
from blaze.
Oops - sorry - I'll blame it on small iPhone screen :) thanks a lot!
from blaze.
When is this coming out? coming soon this summer 2017?
from blaze.
@capensisma: Quoting Mitar (from my pull request):
Waiting for #20 and that we release first community Blaze version. I would like that one to be without extra features, just bugfixes. And then we can start adding features.
from blaze.
Is there anything gating this? @mitar, want me to run some tests first?
from blaze.
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:
{{#tab title="Foo"}}
{{else tab title="Bar"}}
{{else tab title="Baz"}}
{{/tab}}
Feel free to make a pull request like that. With tests and documentation. That would be great!
from blaze.
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.
from blaze.
With 2fa3cab I implemented the Handlebars syntax for chaining block tags. After further consideration I did not implement {{elseif}}
as well because it opens a small backwards incompatibility (somebody could have a template helper named elseif
). Let's try the {{else if}}
syntax and see how it will work. I started to like it, especially because you can use it with custom block tags.
from blaze.
@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.
It was difficult to me to know which packages i had to update. meteor test
was not building the app (because of the if/else if
thingy) even if it had the correct blaze version and it was because templating was not up to date.
Is it written anywhere which packages are needed to be updated?
Again, thanks a lot!
from blaze.
meteor update
should update all? So all packages in this repository.
from blaze.
but meteor update also updates the meteor tool and so on. What if i just want to update blaze?
from blaze.
Released as 2.3.0. You have to update templating package.
Is this mentioned somewhere in the docs? I couldn't find anything. Thanks.
from blaze.
It is documented here: http://blazejs.org/guide/spacebars.html#Chaining-of-Block-Helpers
from blaze.
Thanks @mitar. I expected there to be a mention here: http://blazejs.org/guide/spacebars.html#If-Unless
from blaze.
Feel free to make a pull request. :-)
from blaze.
My blaze version is on 2.3.2. But I still cannot use
{{#if foo}} {{else if boo}} {{else}} {{/if}}
from blaze.
Which version of spacebars-compiler
package you have?
from blaze.
My spacebars-compiler
is @1.1.2
from blaze.
Then please create a small reproduction (a repo showcasing ony this issue).
from blaze.
{{#if isUserProfile}}
<h3>User Profile</h3>
{{else if isLawyerProfile}}
<h3>Lawyer Profile</h3>
{{else}}
<h3>Test</h3>
{{/if}}
Error:
Errors prevented startup:
While processing files with templating-compiler (for target web.browser): client/profile/Profile.html:8: Expected `}}`
...ofile</h3> {{else if isLawyerProfile}...
from blaze.
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.
from blaze.
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.
from blaze.
Can you please add this fix to the documentation of blaze
from blaze.
Related Issues (20)
- Move codebase to ES6 HOT 15
- spacebars-tests packages still uses removed code
- Blaze.remove() destroys DOM before calling onDestroyed() HOT 8
- Error handling, callbacks and DOMRange HOT 9
- Errors in onCreated callback cause a complete stop for rendering further Templates
- Bootstrap select picker is not correctly removed / disposed during Template descruction HOT 6
- Add benchmarks to tests
- SSR is broken in 2.6.0 HOT 4
- Add ts types HOT 3
- Blaze compile errors completely silent if imported HOT 12
- Be able to have more contentBlock in template HOT 1
- Non-primitives not fully reactive in 2.7
- Complete GitHub community standards HOT 7
- CI/CD for documentaiton
- observe-sequence has a bug when _ids have a period HOT 11
- Possibility of a release for people wanting to update to be able to migrate their templates to ASYNC? HOT 4
- Support for async dynamic attributes HOT 3
- Measure performance impact of recent async changes HOT 1
- TypeError: `Cannot convert undefined or null to object` in `waitForAllAttributesAndContinue` HOT 3
- Allowing arbitrary expressions
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blaze.