onRendered is not getting triggered


#1

I created a template in which I dynamically want to render another template (which was registered for a particular type in some other place of the application).

Template:

<template name="renderField">
	{{#if field.type}}
		<!-- a custom rendering is requested - this will be made visible onRendered-->
		<div class="field">
		</div>
	{{else}}
		...
	{{/if}}
</template>

Once the enclosing “renderField”-template is rendered, I wanted to render the custom template.

import { Template } from 'meteor/templating';

Template.renderField.onRendered(function() {
	console.log('onRendered');

	const field = this.data;
	if (field.type && renderers[field.type]) {
		Blaze.renderWithData(Template[renderers[field.type]], field, this.find('.field'));
	}
});

However, the onRendered-function is never executed.

I verified on the frontend, that Template.renderField._callbacks.rendered[0] contains the callback.
What am I missing?

| => meteor --version
Meteor 1.6.0.1    

#2

Are you importing that HTML file with template before your scripts? Are you sure that renderField template is visible?

When using imports/ directory, it is nice to have HTML file import on top of the file which contains all the logic within template.


#3

Thanks for your response! I don’t quite get the question, to be honest. However, changing to onCreated runs the code, so I assume all dependencies are properly managed