Template insert event

Use case or problem

I’d like the ability to create plugins that trigger whenever certain templates are used, such as a tab stop feature. Currently, there’s no event that happens when templates are added, so I can’t get it to work.

Of course, if you want to add the tab stop feature to templates as well, that’d certainly save me some time.

Thanks!

Are you talking about core plugin Templates or community plugin Templater?

Core plugin Templates.

Core plugin Templates doesn’t have a feature of executing custom code. However community plugin Templater can. So you can write in Templater template

Template line 1
Template line 2 with some dynamic content: <% new Date() %>
<%*
// any js that is executed when the template is applied
-%>
Template line 3
Template line 4

You can monkey patch the insertTemplate method from the plugin. I did this for one of my plugins.

But I ran into an issue where calling the original method would result in inconsistent behavior.