spacebars

Return array item by index in a meteor spacebars template

a 夏天 提交于 2019-12-05 00:52:54
I want to access the first item of an array inside a meteor template, I'm using this syntax : <p>{{array[0]}}</p> However it doesn't seem like it's working. I don't want to iterate through values using {{#each}} , just pick the first one from the array. This is just a problem of syntax, the correct one is the following : <p>{{array.[0]}}</p> Notice the . dot between the array property and the brackets (array indexing) notation ? Here is the (hidden) docs for this : https://github.com/meteor/meteor/wiki/Using-Blaze#dotted-helpers-with-numeric-indices 来源: https://stackoverflow.com/questions

ng-repeat + filter like feature in Meteor Blaze/Spacebars

最后都变了- 提交于 2019-12-03 16:38:43
I am from AngularJS background, recently start learning Meteor. In AngularJS, I may have something like: <div ng-repeat="person in persons | filter:search"> <h4>{{person.name}}</h4> <b>{{person.age}}</b> </div> search object can be bound (2-way bound) to HTML textbox. Whenever the textbox changed, the filter will be automatically updated. How to do so in Meteor? I am not familiar with AngularJS, but here is an example of how you would accomplish this with Meteor. This example shows a list of persons, along with an HTML number input that you can use to filter by age the displayed list. client

Meteor Spacebars {{#if someCondition}} shows data briefly on page refresh

寵の児 提交于 2019-12-02 10:29:22
问题 I have tried this a couple different ways and they both behave the same way (see below for code). I'm using a spacebars if condition (and tried using a helper as well) to check if the user is logged in, then display login/sign up links if they aren't. If they are, hide them. What I noticed is that on the initial page load (if they navigate back from a different site), the login/sign up links show quickly before hiding (if the user is still logged in). Is there a way to insure that no elements

Meteor Spacebars {{#if someCondition}} shows data briefly on page refresh

人走茶凉 提交于 2019-12-02 04:41:57
I have tried this a couple different ways and they both behave the same way (see below for code). I'm using a spacebars if condition (and tried using a helper as well) to check if the user is logged in, then display login/sign up links if they aren't. If they are, hide them. What I noticed is that on the initial page load (if they navigate back from a different site), the login/sign up links show quickly before hiding (if the user is still logged in). Is there a way to insure that no elements render in the view if the condition is false? It seems to me that it should check before the view

How to execute a callback after an #each is done?

邮差的信 提交于 2019-12-01 17:31:32
I'm having trouble with a callback after the #each has finished. I have a template named "content": <template name="content"> {{#if Template.subscriptionsReady}} {{#each currentData}} <div data-cid="{{this._id}}"></div> {{/each}} {{else}} Loading... {{/if}} </template> At first I wait for a subscription, when this is available, I iterate through my Collection with {{#each}} and append the div . What I need is a sort of callback for when the for-each loop is done (in other words DOM ready). Template.content.onRendered() -> triggers to early I also tried appending an image after the {{each}} and

Defining iterative block helpers in Meteor 0.8

我是研究僧i 提交于 2019-12-01 12:52:05
Until version 0.8 it was possible to use the regular Handlebars way for defining iterative block helpers such as the popular each_with_key , defined, e.g., here as follows: Handlebars.registerHelper("each_with_key", function(obj, fn) { var context, buffer = "", key, keyName = fn.hash.key; for (key in obj) { if (obj.hasOwnProperty(key)) { context = obj[key]; if (keyName) { context[keyName] = key; } buffer += fn(context); } } return buffer; }); This no longer works in 0.8, and neither the migration guide nor the spacebars documentation show an example for this. Given that block helpers are now

Defining iterative block helpers in Meteor 0.8

谁说我不能喝 提交于 2019-12-01 10:49:29
问题 Until version 0.8 it was possible to use the regular Handlebars way for defining iterative block helpers such as the popular each_with_key , defined, e.g., here as follows: Handlebars.registerHelper("each_with_key", function(obj, fn) { var context, buffer = "", key, keyName = fn.hash.key; for (key in obj) { if (obj.hasOwnProperty(key)) { context = obj[key]; if (keyName) { context[keyName] = key; } buffer += fn(context); } } return buffer; }); This no longer works in 0.8, and neither the

Meteor - What is Spacebars.kw {hash: Object}

本小妞迷上赌 提交于 2019-12-01 02:49:41
问题 I'm attempting to write a Meteor package which can be placed inside templates. So I first attempted to register a helper. Template.registerHelper('testHelper', function(a, b) { console.log(a); console.log(b); }) I've added the package inside /packages , and in my client template, when I added {{testHelper "hello" "meow"}} , the console logged hello and meow , which is what I expected. When I added {{testHelper "hello"}} , I expected the console to log hello and null , since nothing was passed

How Do I Access an Object's Properties From a Template?

假如想象 提交于 2019-12-01 00:33:40
问题 According to http://handlebarsjs.com/expressions.html, I should be able to do this: <h1>{{article.title}}</h1> But I can't seem to get this to work in meteor. Here's my template: <template name="content"> {{#if item}} <p>{{item.name}}</p> {{/if}} </template> Here's the JavaScript that returns the item: Template.content.item = function() { return Items.findOne({ _id: Session.get("list_id") }); }; And yes, the item does indeed have a property called name :-) When I do this, I see an error in

How do I Register Meteor Spacebars Helpers?

笑着哭i 提交于 2019-11-30 19:01:56
问题 Trying to make some simple handlebars helpers Handlebars.registerHelper('if_eq', function(context, options) { if (context == options.hash.compare) return options.fn(this); return options.inverse(this); }); Getting this error. ReferenceError: Handlebars is not defined What's the correct way to do it. 回答1: the Handlebars object is only available on the client. So make sure you have if (Meteor.isClient) { } wrapped around the helper registration code 来源: https://stackoverflow.com/questions