logo
down
shadow

Meteor How to call one template helper into another helper?


Meteor How to call one template helper into another helper?

Content Index :

Meteor How to call one template helper into another helper?
Tag : meteor , By : ponchopilate
Date : November 28 2020, 08:01 AM

hope this fix your issue For common / shared code that needs to be accessed by more than one Template it makes sense to define a global helper using Template.registerHelper.
For your helper this would look like this:
// import { Trb } from ....

Template.registerHelpers('myTrb', function myTrb () {
  const user = Meteor.user();
  if (! user) return [];
  const tribIOwn = user.trb_i_own; 
  const trb = [];
  tribIOwn.forEach(function (t) {
    trb.push(Trb.findOne({_id: t}));
  });
  return trb
})

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Exception in template helper using global helper in Meteor


Tag : javascript , By : Ir0nh1de
Date : March 29 2020, 07:55 AM
To fix the issue you can do I added a global helper function with UI.registerHelper which returns a String. If I access the particular site, I can see the correct output, but I get the following exception: , Try adding some checks:
UI.registerHelper('levelMode', function() {
  if (typeof Games !== 'undefined' && Games != null)
    var game = Games.findOne({_id: this._id});
    if (game != null && game.mode)
      return 'Difficult';
  return 'Easy';
});

Calling one helper from another helper within the context of a template (Meteor 0.9.4)


Tag : javascript , By : user177910
Date : March 29 2020, 07:55 AM
seems to work fine Sorry if I'm being dull, but couldn't you declare the function as an object and assign it to multiple helpers? For instance:
// Common methods
doCommonThing = function(instance) // don't use *var* so that it becomes a global
{
    /* Commonly used method is defined here */
}

Template.myTemplate.helpers({
    otherThing1: function() {
        var _instance = this; // assign original instance *this* to local variable for later use
        /* Do proprietary thing here */
        doCommonThing(_instance); // call the common function, while passing in the current template instance
    },
    otherThing2: function() {
        var _instance = this;
        /* Do some other proprietary thing here */
        doCommonThing(_instance);
    }
});

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


Tag : meteor , By : MJRider
Date : March 29 2020, 07:55 AM
seems to work fine This like using of common code, you can make another javascript function which contains the your reusable code and call it from wherever you required.
Like in your code-
function calcField(field){
   return field * 25 / 100
}
Template.XXX.helpers({
    reusableHelper: function() {
        return calcField(this.field1); 
    },
    anotherHelper: function() {
        if (calcField(this.field1) > 300) 
            return calcField(this.field1) + ' is greater than 300'; 
        else
            return calcField(this.field1) + ' is smaller than 300';
    }
});

Meteor - How call another function in same template helper


Tag : javascript , By : user179863
Date : March 29 2020, 07:55 AM
help you fix your problem There is a trick that you can use meteor execute the functions call from right to left so your one function output will be because input for the another function and so on. I hope that make sense to you.
Your html code
<template name="hello">
    {{getDaysInParticularMonth getDaysInMonth}} 
</template>
Template.hello.helpers({
  getDaysInMonth: function(){
    var now = new Date();
    return [now.getMonth(), now.getFullYear()];
  },
  getDaysInParticularMonth: function(array) {
     console.log("hey"); 
     return 0;     //just for test
  },
});
<template name="hello">
    {{getDaysInMonth}} 
</template>
Template.hello.helpers({
  getDaysInMonth: function(){
    var now = new Date();
    return getDaysInParticularMonth(now.getMonth(), now.getFullYear());
  },

});

function getDaysInParticularMonth(month, year) {
     console.log("hey"); 
     return 0;     //just for test
},

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


Tag : javascript , By : Ricardo
Date : March 29 2020, 07:55 AM
Related Posts Related QUESTIONS :
shadow
Privacy Policy - Terms - Contact Us © scrbit.com