Here's the template structure
{{#each loadedEvents}}
{{#if future}}
{{#if timezone="Europe/Warsaw"}}
{{> event}}
{{/if}}
{{/each}}
Is that possible to view only items with given value? And the second question, how to combine this two statements:
{{#if future}} {{#if timezone="Europe/Warsaw"}}
You can create a dedicated helper to check if a timezone is equal to a certain value :
Template.loadedEvents.helpers({
timezoneIs: function(timezone){
return this.timezone == timezone;
}
});
If you want to combine two Spacebars {{#if}}
block helpers, once again create a dedicated helper that performs the test in JS :
JS
Template.loadedEvents.helpers({
isFutureAndTimezoneIs: function(timezone){
return this.future && this.timezone == timezone;
}
});
HTML
{{#each loadedEvents}}
{{#if isFutureAndTimezoneIs "Europe/Warsaw"}}
{{> event}}
{{/if}}
{{/each}}
Use Template.registerHelper
to create a global helper. For instance, to create a helper that compares two arbitrary variables:
Template.registerHelper('compare', function(v1, v2) {
if (typeof v1 === 'object' && typeof v2 === 'object') {
return _.isEqual(v1, v2); // do a object comparison
} else {
return v1 === v2;
}
});
Then use it using:
{{#if compare timezone "Europe/Warsaw"}}
// Do something
{{/if}}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With