Benjamin
Benjamin

Reputation: 70

Meteor Ironrouter - how to waiton (with a loading template) a Session.get?

I'm trying to render a 'spotresult' template with some variable (from Session.get()). I've spent a lot of time on it but I didn't find an answer ... Could you help me please ?

https://git.geekli.st/balibou/hackaton_volant/tree/master/cerfvolantspatial

Thanks a lot !

//router.js
Router.configure({
  layoutTemplate: 'layout',
  loadingTemplate: 'loading'
});

Router.route('/', {name: 'spot'});

// 1.Normal rendering
//Router.route('/spotresult',{name: 'spotresult'});

-----------------------------------------------------------------------------

// 2. First attempt
//Router.route('/spotresult', {
//  name: 'spotresult',
//  action: function () {
//    if (this.ready())
//      this.render();
//    else
//      this.render('loading');
//  }
//});

//3. Second attempt
//var waitingSession = function() {
//  if (!this.ready()) {
//    this.render(this.loadingTemplate);
//  } else {
//    this.next();
//  }
//}
//
//Router.onBeforeAction(waitingSession, {only: 'spotresult'});

Layout template:

<template name="layout">
  <div class="container">
    {{> header}}
  </div>
  <div class="container mainyield">
    {{> yield}}
  </div>
</template>

Loading template:

<template name="loading">
  {{>spinner}}
</template>

Spot template:

<template name="spot">
  <div class="spot">
    {{#if currentUser}}       
      <p class="text-center">Bonjour, bienvenue sur votre profil</p>   
    {{else}}
      <h4 class="text-center">Bonjour, pour connaître la vitesse du vent, remplissez le champs ci-dessous !</h4>
      <form role="form" class="new-spot">
        <div class="form-group">
          <label for="email">Spot :</label>
          <input name="lieu" type="text" class="form-control" id="lieu" placeholder="Entrez un lieu">
        </div>
        <button type="submit" class="btn btn-default">Valider</button>
      </form>   
      {{#if windspeed7}}
        {{>spotresult}}
      {{/if}}  
    {{/if}} 
  </div>
</template>

Upvotes: 1

Views: 580

Answers (1)

Ethaan
Ethaan

Reputation: 11376

i think the problem is here, replace with this code.

Template.spot.helpers({
  showSpinner:function(){
    if(Session.get("windspeed7" === ''){
      return true;
    }else{
      return false;         
    }
  }
});

And add this helper inside the other helper

 {{#if showSpinner}}
   {{else}}
    {{>spinner}}
   {{/if}}

This should work

Upvotes: 1

Related Questions