Meteor Spacebars {{#if someCondition}} shows data briefly on page refresh

前端 未结 3 1160
独厮守ぢ
独厮守ぢ 2021-01-24 18:16

I have tried this a couple different ways and they both behave the same way (see below for code). I\'m using a spacebars if condition (and tried using a helper as well) to check

3条回答
  •  感情败类
    2021-01-24 18:38

    Are you sure you're thinking about this correctly?

    isUserLoggedIn: function() { // implies you're checking for the user
        var user = Meteor.user(); // if there's a user this returns true
    
        if(user) { // you're saying if there's a user ...
            return false; // return false
        } else{ // and if there isn't
        return true; // return true
        }
    }
    

    Basically you're saying "is the user logged in" and if yes "return false" which is making you double think. Instead, reverse your logic.

    isUserLoggedOut: function() { // implies you're checking for the user
        var user = Meteor.user(); // if there's a user this returns true
    
        if(user) { // there is a user
            return false; // so isUserLoggedOut == false
        } else{ // and if there isn't a user
            return true; // isUserLoggedOut == true
        }
    }
    

    Now your template becomes easy

    {{#if isUserLoggedOut}}
       {{>loggedOutTemplate}}
    {{/if}}
    

提交回复
热议问题