0
votes

I'm struggling with what was supposed to be simple and I can't get it. Is there a bug or is it just me? I've created two simple examples using two approaches: 1)registerHelper and 2)parentData: The HTML is:

<body>
    This is the body
   {{> A}}
</body>

 <template name="A">
     This is "A"
        {{> B}}
    </template>

    <template name="B">
        This is "B"
        {{> C}}
    </template>

    <template name="C">
        This is "C"
        {{foo}}
    </template>

And the Javascript for 1) is:

 Template.registerHelper(foo, function () {
    return 'Hello';
});

And for case 2) is:

Template.A.helpers({
  foo: function () {
      return 'Hello';
  }
});

Template.C.helpers({
  foo: function () {
    return Template.parentData(2);
  }
});

What is wrong?

1

1 Answers

0
votes

It looks like you are trying to invoke the helper function infoMessage of the parent template. This is not the same as accessing the parent data context. For your use-case, I recommend registering a helper function that any template, including A and B, can use:

Template.registerHelper("infoMessage", function (dataContext) {
    return dataContext.infoMessage;
});

EDIT: With your edited question, you are missing the quotation marks around "foo" in (1):

Template.registerHelper("foo", function () {
  return 'Hello';
});

Then use it in your templates:

<template name="A">
    <div class="message info-message">{{> B}}{{infoMessage .}}</div>
</template>

<template name="B">
    <div class="wrap-popup">
        <div class="popup-img"><img src="check12.svg"></div>
        <div class="popup-item">
            <h1> Sucess</h1>
            <p>{{infoMessage ..}}Nada...</p>
        </div>
    </div>
</template>

See official Meteor docs on registering helpers for more.