How to add onRendered from onCreated?

292 views
Skip to first unread message

Manuel De Leon

unread,
Feb 20, 2015, 6:25:50 PM2/20/15
to meteo...@googlegroups.com
I'm working with the dev branch. I want to add an onRendered dynamically from the onCreated event. How can I do that?

The following doesn't work (the event doesn't fire) :

Template.hello.onCreated(function () {
this.view.template.onRendered(function (
{
console.log("Added dynamically.");
});
});

Slava Kim

unread,
Feb 20, 2015, 6:26:45 PM2/20/15
to meteo...@googlegroups.com
I think adding such callbacks dynamically for an object that was already instantiated doesn't work by design.

Manuel De Leon

unread,
Feb 20, 2015, 6:59:36 PM2/20/15
to meteo...@googlegroups.com
Why wouldn't you want people to be able to say "run this code when this particular instance is rendered (aside from whatever other rendered events) "?

If not from the created, then how can I add an onRendered to all templates? So I can check if a template variable was set during creation and then do something.

I have a package where I want to run code on a user's template rendered event if they call my library from the created event. Right now I can add helpers dynamically from the created event. I would like to do the same for onRendered.

Manuel De Leon

unread,
Feb 20, 2015, 7:37:30 PM2/20/15
to meteo...@googlegroups.com
My ideal scenario is to be able to the add a method to all templates that when called from onCreated it sets something to run on rendered. e.g. if you add my package you'd be able to do:

Template.home.onCreated({
  this.addStuff();
});

// And addStuff would then add helpers and code to be run when the template renders.

I thought I'd be able to do so with the new onRendered. Is there a way to do this?
Reply all
Reply to author
Forward
0 new messages