[solved] How to get template name in tpl callback?


#1

Hey all! This sd be an easy one :smile:
How can I get template name in onRendered callback?


#2

This is not as easy as you hoped…

this.view.name

will get you the view name of the current template instance

The reason its not straight forward is that you never need to address a template by it’s name after it is instantiated - you would use the Template.instance() method, or in the template callbacks the this keyword, which is a shortcut to the template instance

e.g.

Template.toolbar.onRendered(function () {
    console.log(this.view.name)
});

logs ‘Template.toolbar’


#3

Works nice and simple. Thanks a lot)