Reputation: 105
I am using meteor. I have a template which looks like this,
<template name="SearchAct">
{{#each SearchPerson}}
<div class="result"><!--This is one search result box-->
<div class="resultContent">
<img src={{payload.pic_square}} alt="profile photo" class="floatLeft" />
<p>{{payload.uid}}</p>
<span class="floatLeft">
{{payload.first_name}}
<br/>
{{payload.last_name}}
</span>
<input type="checkbox" class="floatRight" />
<h4>Tennis</h4>
<span class="age_location">
{{#if payload.birthday}}
{{payload.birthday}},
{{/if}}
{{#if payload.sex}}
{{payload.sex}}
{{/if}}
<br/>
{{#if payload.hometown_location}}
{{payload.hometown_location.city}},
{{payload.hometown_location.state}},
{{payload.hometown_location.country}}
{{/if}}
</span>
<div class="line"></div>
<a href="#" class="clear" onclick="renderProfile({{payload.uid}});">See Their Details</a>
</div><!-- End of resultContent-->
</div><!-- End of result box-->
{{/each}}
</template>
Now I want to check a null value for {{payload.birthday}}
. Here if I get null
value, I want to display a message. How could I check a null
value?
Upvotes: 5
Views: 3045
Reputation: 410
I think you can try this, you can use count
if value birthday
eql 0 is false, it's work for me
<span class="age_location">
{{#if payload.birthday.count}}
{{payload.birthday}}
{{else}}
you display message
{{/if}}
</span>
ref: https://groups.google.com/forum/#!topic/meteor-talk/Gumkz9VnLYY
Upvotes: 2
Reputation: 7366
Handlebars (and by extension Meteor) doesn't allow logic inside templates. Therefore, you need to extend your template, or all your project's templates, with a Handlebars helper. Put the following in any client-loaded JavaScript file in your project:
Handlebars.registerHelper("isNull", function(value) {
return value === null;
});
Then you can use it in your template as a parameter for your if
:
{{#if isNull payload.birthday}}Your birthday is null!{{/if}}
Upvotes: 3
Reputation: 6470
I think you just need an {{else}}
in there:
<span class="age_location">
{{#if payload.birthday}}
{{payload.birthday}}
{{else}}
No birthday found
{{/if}}
</span>
Upvotes: 4