meteor-helper

Change Body Class Based On URL in Meteor

ぃ、小莉子 提交于 2019-12-01 01:40:02
I have a template named layout in my app. Inside has: <body id="body class="{{blue}}> Basically what I want to achieve is that when you hit a url, for example, www.abc.com/sky, I want to add a body class of blue: <body id="body class="blue"> In my client folder I have this but seems not to work: Template.layout.helpers({ blue: function() { var loc = window.location.href; // returns the full URL if(/sky/.test(loc)) { $('#body').addClass('blue'); } } }); I am new to the javascript world and I am following a tutorial but the tutorial was not aimed for Meteor. You shold modify DOM elememts in

Change Body Class Based On URL in Meteor

谁说我不能喝 提交于 2019-11-30 19:04:13
问题 I have a template named layout in my app. Inside has: <body id="body class="{{blue}}> Basically what I want to achieve is that when you hit a url, for example, www.abc.com/sky, I want to add a body class of blue: <body id="body class="blue"> In my client folder I have this but seems not to work: Template.layout.helpers({ blue: function() { var loc = window.location.href; // returns the full URL if(/sky/.test(loc)) { $('#body').addClass('blue'); } } }); I am new to the javascript world and I

How Do I Make A Meteor Helper Non-Reactive?

删除回忆录丶 提交于 2019-11-28 12:17:07
I want to make this code non reactive. Is there a way? Template.foo.helpers({ info: function(){ var user = Meteor.user(); if (user && user.profile) return user.profile.info; } }); I know there is a way when you are Foo.find({}, {reactive:false}) I was wondering if there was a equivalent. I think what you are looking for is the Tracker.nonreactive(func) function described here . Per the documentation, you need to pass a function to this function to be executed and the result of that function will be returned by this function. Also, this function will not pay attention to any reactive data

How do you call a Meteor template helper from the console or other JS code?

天大地大妈咪最大 提交于 2019-11-28 11:30:12
I've defined a template helper in Meteor, say Template.postsList.helpers({ filteredPosts: function getPosts() { return Posts.find(...); } }); How can I debug that template helper from the console, and how can I reuse it from other code in the app? Wanting to call the helper from elsewhere in the app suggests that you should factor it out in a function. To quickly debug the helper, evaluate this in the client console: Template.postsList.__helpers.get('filteredPosts')(...parameters); There is a package that might help with debugging templates and template helpers: prasad19sara:client-debugger .

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

How Do I Make A Meteor Helper Non-Reactive?

有些话、适合烂在心里 提交于 2019-11-27 06:52:21
问题 I want to make this code non reactive. Is there a way? Template.foo.helpers({ info: function(){ var user = Meteor.user(); if (user && user.profile) return user.profile.info; } }); I know there is a way when you are Foo.find({}, {reactive:false}) I was wondering if there was a equivalent. 回答1: I think what you are looking for is the Tracker.nonreactive(func) function described here. Per the documentation, you need to pass a function to this function to be executed and the result of that

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