meteor - Why Is Wrong Spacebars #if Block Executed? -
i trying write if else statement in spacebars template inside meteor app shown below, unfortunately getting 3 blocks processed though 1 returning true, wondering if can please tell me doing wrong / missing here , how resolve it? thanks
<template name="header"> <nav class="navbar navbar-default navbar-static-top" role="navigation"> <div class="container"> <div class="navbar-header"> <a class="navbar-brand" href="{{pathfor 'home'}}">{{ sitetitle }}</a> </div> <div class="collapse navbar-collapse" id="main-nav"> {{#if currentuser}} <ul class="nav navbar-nav navbar-right"> {{#if isappadmin}} <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown"> <i class="fa fa-tasks"></i> admin <i class="fa fa-caret-down"></i> </a> </li> {{else}} {{#if isprouser}} <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown"> <i class="fa fa-tasks"></i> pro user <i class="fa fa-caret-down"></i> </a> </li> {{/if}} {{/if}} <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown"> <i class="fa fa-user"></i> {{ currentuser.profile.name }} <i class="fa fa-caret-down"></i> </a> </li> </ul> {{else}} <div class="navbar-right"> <a href="{{ pathfor 'entrysignin' }}" class="btn btn-default navbar-btn">sign in</a> <a href="{{ pathfor 'entrysignup' }}" class="btn btn-primary navbar-btn">register</a> </div> {{/if}} </div> </div> </nav> </template>
header.js
template.header.helpers({ isprouser: function () { var retval = meteor.user().profile.sholdertype == 'prouser' ? 'true' : 'false'; return retval; }, isappadmin: function () { var retval = meteor.user().profile.sholdertype == 'admin' ? 'true' : 'false'; return retval; } });
you returning string while if expecting boolean, change
template.header.helpers({ isprouser: function () { var retval = meteor.user().profile.sholdertype == 'prouser' ? 'true' : 'false'; return retval; }, isappadmin: function () { var retval = meteor.user().profile.sholdertype == 'admin' ? 'true' : 'false'; return retval; } });
to:
template.header.helpers({ isprouser: function () { var retval = meteor.user().profile.sholdertype == 'prouser' ? true : false; return retval; }, isappadmin: function () { var retval = meteor.user().profile.sholdertype == 'admin' ? true : false; return retval; } });
and should work.
Comments
Post a Comment