#Unless is not working

Hi,

As you can see I have no customers in my collection.

So why does this code not work?

Template.OEMPartner.helpers({
    customers() {
        return Customers.find({}, { sort: { checked: -1 } });
    },
 {{#unless customers}}
        <div class="ui icon message">
            <img class="icon" src="images/customers.png">
            <div class="content">
                <div class="header">
                    No customers
                </div>
                <li>You have no customers in your shop.</li>
                <li>Let's insert some by hand, in the add new customer box above </li>
                <li>Or press the blue arrow, next to the generate button, to insert some dummy customers for our Fictive SaaS environment </li>
            </div>
        </div>
        {{else}}
        <h4> 
        <img class="icon" src="images/customers.png">
        {{NrCustomers}} Customers stored in the database of our fictive SaaS platform </h4>
        <table class="ui celled striped table">
            <thead>
                <tr>
                    <th>Customer</th>
                    <th>Delete customer</th>
                    <th>Generate Stream</th>
                </tr>
            </thead>
            <tbody>
                {{#each customers}} {{> customer}} {{/each}}
            </tbody>
        </table>
        {{/unless}}

#unless will take only boolean value right?

well

unless is the opposite of if, so I think my code should have worked. I now moved it back to if (noCustomers) and that works perfectly. So I think we have a bug.

Js

Template.pet.helpers({  
  dog: {
    name: 'Spot',
    age: 3,
    sleeping: false
  }
});

Template

<template name="pet">  
  {{#unless dog.sleeping}}
    {{dog.name}} is awake!
  {{else}}
    {{dog.name}} is sleeping!
  {{/unless}}
</template>  

1 Like

Customers is an empty array [] not null/undefined so it’s truthy. Try {{#unless customers.length}}.

1 Like

hahaha! thanks… that explains it… I thought it was falsy because of javascripts falsy rules… cool…

this works (I do the check now in my helper)

 {{#if noCustomers}}
        <div class="ui icon message">
            <img class="icon" src="images/id.png">
            <div class="content">
                <div class="header">
                    <h4>No users</h4>
                </div>
                <p> Please insert at least one user in a customer so we can simulate the Single Sign on</p>
            </div>
        </div>
        {{else}}