Greg Bluntzer
Greg Bluntzer

Reputation: 333

Meteor.js : How to get the name of a Template from the Template?

Lets say I have a definition of a template in a html file.

<template name="myTemplate">

Now in javascript I want to get the value that is name in template by referencing the Template itself to avoid typing mistakes and to allow intellij ide ctrl clicking of the template to take me to the template.

I want something like.

let stringValueOfTemplateName = Template.myTemplate.name

Instead of having to do

let stringValueOfTemplateName = "myTemplate"

Is there any way to access the name?

Upvotes: 1

Views: 313

Answers (2)

mutdmour
mutdmour

Reputation: 543

Template.captureView.viewName.replace('Template.',''))

or

Template.instance().view.name.replace('Template.',''))

Upvotes: 1

Zoltan Toth
Zoltan Toth

Reputation: 47667

Try

let stringValueOfTemplateName = Template.instance().view.name.replace('Template.', '');

Upvotes: 1

Related Questions