0
votes

Weird problem with Meteor. I had been using Template.layout.render to run a javascript function whenever a page loads that uses the layoutTemplate called layout. It was working, firing code whenever the layout template was rendered, but it recently stopped working.

Code example, in layout.js:

Template.layout.created = function() {
  alert("created");
}
Template.layout.rendered = function() {
  alert("foo");
}

The Template.layout.created works fine (I see its popup). But the Template.layout.rendered does not run at all. No popup, or any other code I put in that block.

Other pages work with their Template.name.rendered code. For example, in index.js:

Template.index.rendered = function() {
  alert("index rendered");
}

That works. I see a index rendered popup.

Anyone seen anything like this?

I am using Iron Router, though I doubt the problem is with Iron Router, here is the config:

Router.configure({
  layoutTemplate: 'layout',
});
Router.route('/', {
  name: 'index',
});
1
I don't see anything wrong with the code you are showing. The rendered callback should be called at least once, after the template is first done rendering into the DOM. If it never gets that far there may be something wrong with the template. - illuminaut
Thanks for your comment. I just figured out the problem. There was a duplicate Template.layout.rendered in another .js file elsewhere in the code. It was put there by accident, and when I removed it, everything is working fine again. - Crash Override

1 Answers

0
votes

Found my problem, and I apologize for the post.

There was a duplicate Template.layout.rendered defined in another javascript file elsewhere in another js file.

So I hope this helps someone else having the same problem. If your Template.whatever.rendered stops working, look in your recently-added javascript files for a duplicate Template.whatever.rendered. Meteor and Iron Router do not produce a warning or error when duplicate ones exist. Perhaps they should? Hint hint