Code Monkey home page Code Monkey logo

Comments (33)

mitar avatar mitar commented on May 21, 2024 7

Released as 2.3.0. You have to update templating package.

from blaze.

mitar avatar mitar commented on May 21, 2024

Does handlebars have it?

from blaze.

mitar avatar mitar commented on May 21, 2024

The issue is that this might seem a simple addition but would require a lot of changes internally. Like, a lot.

from blaze.

ramezrafla avatar ramezrafla commented on May 21, 2024

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.

mitar avatar mitar commented on May 21, 2024

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.

ramezrafla avatar ramezrafla commented on May 21, 2024

Got it :) -- will start digging into it. Is the parser part of this repo or somewhere else?

from blaze.

mitar avatar mitar commented on May 21, 2024

https://github.com/meteor/blaze/tree/master/packages/spacebars-compiler

from blaze.

AdrienTorris avatar AdrienTorris commented on May 21, 2024

totally agreed with this issue. Simple if/else if/else is just so usefull

from blaze.

akanix42 avatar akanix42 commented on May 21, 2024

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}}

from blaze.

ramezrafla avatar ramezrafla commented on May 21, 2024

Excellent @nathantreid,
Can you PR with your changes?

from blaze.

akanix42 avatar akanix42 commented on May 21, 2024

@ramezrafla Check out the PR link above my previous post. 😄

from blaze.

ramezrafla avatar ramezrafla commented on May 21, 2024

Oops - sorry - I'll blame it on small iPhone screen :) thanks a lot!

from blaze.

x5engine avatar x5engine commented on May 21, 2024

When is this coming out? coming soon this summer 2017?

from blaze.

akanix42 avatar akanix42 commented on May 21, 2024

@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.

ramezrafla avatar ramezrafla commented on May 21, 2024

Is there anything gating this? @mitar, want me to run some tests first?

from blaze.

mitar avatar mitar commented on May 21, 2024

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.

ramezrafla avatar ramezrafla commented on May 21, 2024

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.

mitar avatar mitar commented on May 21, 2024

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.

namirsab avatar namirsab commented on May 21, 2024

@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.

mitar avatar mitar commented on May 21, 2024

meteor update should update all? So all packages in this repository.

from blaze.

namirsab avatar namirsab commented on May 21, 2024

but meteor update also updates the meteor tool and so on. What if i just want to update blaze?

from blaze.

maxfi avatar maxfi commented on May 21, 2024

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.

mitar avatar mitar commented on May 21, 2024

It is documented here: http://blazejs.org/guide/spacebars.html#Chaining-of-Block-Helpers

from blaze.

maxfi avatar maxfi commented on May 21, 2024

Thanks @mitar. I expected there to be a mention here: http://blazejs.org/guide/spacebars.html#If-Unless

from blaze.

mitar avatar mitar commented on May 21, 2024

Feel free to make a pull request. :-)

from blaze.

wei170 avatar wei170 commented on May 21, 2024

My blaze version is on 2.3.2. But I still cannot use
{{#if foo}} {{else if boo}} {{else}} {{/if}}

from blaze.

mitar avatar mitar commented on May 21, 2024

Which version of spacebars-compiler package you have?

from blaze.

wei170 avatar wei170 commented on May 21, 2024

My spacebars-compiler is @1.1.2

from blaze.

mitar avatar mitar commented on May 21, 2024

Then please create a small reproduction (a repo showcasing ony this issue).

from blaze.

wei170 avatar wei170 commented on May 21, 2024
{{#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.

mitar avatar mitar commented on May 21, 2024

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.

wei170 avatar wei170 commented on May 21, 2024

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.

Roshdy avatar Roshdy commented on May 21, 2024

Can you please add this fix to the documentation of blaze

from blaze.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.