spacebars

Multiple yield in Meteor.js application template

≯℡__Kan透↙ 提交于 2019-11-30 15:21:44
I have one general {{>yield}} for iron-router in a layout file which renders my pages, which are templates. In one of my pages, I have a side menu and according to the selection in this menu, I want to load different templates related to this page in this page. How can I achieve this? I have done a similar thing using iron-router's layout template option. Say I want to create a home view with multiple views/templates inside of this home view that will change. First I would declare my route: Router.map(function () { this.route('home', { path: '/', template: 'myHomeTemplate', layoutTemplate:

Meteor: Access Template Helper (or variable) from another helper

蹲街弑〆低调 提交于 2019-11-28 08:12:05
How can I reference a template helper from another one? For example... Template.XXX.helpers({ reusableHelper: function() { return this.field1 * 25 / 100; //or some other result }, anotherHelper: function() { if (this.reusableHelper() > 300) //this does not work return this.reusableHelper() + ' is greater than 300'; else return this.reusableHelper() + ' is smaller than 300'; } }); I have also tried Template.instance().__helpers.reusableHelper - all with no luck. Alternatively is there a way to define reactive Template instance variables? XXX is a sub-template that renders multiple times on the

Check for equality in Spacebars?

半城伤御伤魂 提交于 2019-11-27 02:36:38
问题 I am trying to do what I think should be a very simple task, but have been failing to do so in the past hour. I want to select a select option by default if the user property matches the value. <select name="myName"> {{#each addKeys myTable}} <!-- addKeys creates variables for keys and values --> <option value="{{key}}" {{#if currentUser.property === key}}selected="selected"{{/if}}>{{value}}</option> {{/each}} </select> Now I thought this was straightforward enough to be implemented. But it

Meteor: Access Template Helper (or variable) from another helper

一世执手 提交于 2019-11-27 02:11:56
问题 How can I reference a template helper from another one? For example... Template.XXX.helpers({ reusableHelper: function() { return this.field1 * 25 / 100; //or some other result }, anotherHelper: function() { if (this.reusableHelper() > 300) //this does not work return this.reusableHelper() + ' is greater than 300'; else return this.reusableHelper() + ' is smaller than 300'; } }); I have also tried Template.instance().__helpers.reusableHelper - all with no luck. Alternatively is there a way to

How can I get the index of an array in a Meteor template each loop?

十年热恋 提交于 2019-11-26 15:26:04
Say I have an object, someObject: { foo: "apple", myArray: ["abc", "def"] } And a template helper that looks like this (and works fine): getArray: function(){ var self = this; self.myArray = self.myArray || []; return self.myArray; } How should I construct the html to get the array index? I've tried: <template name="someObject"> // takes someObject as data {{#each getArray}} <div class="item" data-value="{{WHAT GOES HERE?}}">{{this}}</div> {{/each}} </template> In which case this successfully returns "abc" and "def" . Which is good. But how can I get the index of the array to put into the