Giter Site home page Giter Site logo

Support for {{#else}} ? about tko HOT 6 CLOSED

knockout avatar knockout commented on May 22, 2024
Support for {{#else}} ?

from tko.

Comments (6)

mbest avatar mbest commented on May 22, 2024 1

It needs to be like this

{{#if loggedIn}}
<li><a href="#">New Request</a></li>
<li><a href="#">Trips</a></li>
<li><a href="#" data-bind="click: logout">logout</a></li>
{{/if}}
{{#else}}
<li><a href="#" data-bind="click: login">login</a></li>
{{/else}}

from tko.

brianmhunt avatar brianmhunt commented on May 22, 2024

Hi Dave - operating on mobile so hard to type this out 😀 but there are two options for else. One is using <!-- else --> inside an if/unless/ifnot binding (no #), the other is having a "peer" {{#else}} binding. I can't see the example on my phone but I hope this gives you something to go on. :)

from tko.

brianmhunt avatar brianmhunt commented on May 22, 2024

... in any case please leave this open as I'd like to put an example in the docs!

from tko.

davetropeano avatar davetropeano commented on May 22, 2024
  1. I had to clean up my markdown comment with the correct link to JSBin.
  2. Here's a sample code snippet I'd like to be able to implement. The basic pattern (to me) is that for every control-y virtual binding we should have an equivalent {{#}}
  <ul>
    <li>Home</li>
   
    {{#if loggedIn}}
    <li><a href="#">New Request</a></li>
    <li><a href="#">Trips</a></li>
    <li><a href="#" data-bind="click: logout">logout</a></li>
    {{#else}}
    <li><a href="#" data-bind="click: login">login</a></li>
    {{/if}}
  </ul>

from tko.

brianmhunt avatar brianmhunt commented on May 22, 2024

I've updated the if-binding documentation, here: http://www.tko.io/a/if-binding.html

The alternative to two {{#...}} blocks is to use <!-- else --> like this:

<ul>
    <li>Home</li>
   
    {{#if loggedIn}}
    <li><a href="#">New Request</a></li>
    <li><a href="#">Trips</a></li>
    <li><a href="#" data-bind="click: logout">logout</a></li>
    <!-- else -->
    <li><a href="#" data-bind="click: login">login</a></li>
    {{/if}}
</ul>

Ideally we'd have support builtin for a mustache equivalent e.g. {{ else }}, and have the {{# else }} binding check to see if it's already inside an if binding so cases like you've highlighted above with {{# if ... }}...{{# else }}...{{/ if }} would behave as expected.

from tko.

brianmhunt avatar brianmhunt commented on May 22, 2024

Closing this as the solution is discussed, but we can re-open if there's something to add, here.

from tko.

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.