logo
down
shadow

Meteor Block Helper that acts like a template


Meteor Block Helper that acts like a template

By : abhishek narayan
Date : November 21 2020, 04:03 PM
I wish this helpful for you Meteor's new Blaze template engine solves this problem quite nicely.
Here's an excerpt from the Blaze docs showing how they can be used.
code :
<template name="ifEven">
  {{#if isEven value}}
    {{> UI.contentBlock}}
  {{else}}
    {{> UI.elseBlock}}
  {{/if}}
</template>

Template.ifEven.isEven = function (value) {
  return (value % 2) === 0;
}
{{#ifEven value=2}}
  2 is even
{{else}}
  2 is odd
{{/ifEven}}


Share : facebook icon twitter icon
Exception in template helper using global helper in Meteor

Exception in template helper using global helper in Meteor


By : Tajuandi Teydey
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:
code :
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)

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


By : user2586774
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:
code :
// 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

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


By : ryan
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-
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';
    }
});
How to pass meteor template helper as a parameter to meteor event handler?

How to pass meteor template helper as a parameter to meteor event handler?


By : fred roach
Date : March 29 2020, 07:55 AM
may help you . Return functions inside your helpers instead of directly putting the code you want to execute :
code :
Template.buttonGroup.helpers({
  onButton1Click: function() {
    return function(event, template){
      console.log('button 1 is clicked');
    };
  },
  onButton2Click: function() {
    return function(event, template){
      console.log('button 1 is clicked');
    };
  }
});

Template.button.events({
  "click": function(event, template) {
    if (this.onClick) {
      this.onClick(event, template);
    }
  }
});
Meteor How to call one template helper into another helper?

Meteor How to call one template helper into another helper?


By : Dogo
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:
code :
// 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
})
shadow
Privacy Policy - Terms - Contact Us © festivalmusicasacra.org