How to override a template.hbs from a plugin

Dear all,

Let’s say I’d like to override a hbs template from a plugin, like the amazing Events plugin.
I’ve tried the following scripts:

<script type="text/x-handlebars" data-template-name="components/events-calendar-day">
   ***some stuff so category icon could be displayed instead of circle***
<script type="text/x-handlebars" data-template-name="/plugins/discourse-events/assets/javascripts/discourse/templates/components/events-calendar-day">
   ***some stuff so category icon could be displayed instead of circle***

but they are not executed. I guess the template is not found at that location, so how can I access it ? Are plugins templates in their own directory ? If so, where ? This is not explained in the theme guide.

Thanks in advance !

I will make sure to add instructions on this to the main guide, but for now, take a look at my response:


Thanks a lot but that does not answer my usecase:

As far as I understand, the «root» folder is (discourse/app/assets/javascripts/discourse/app/templates/) so I can access a component in a subfolder from this path.

But the template I want to access is in:
which is not a subfolder of the first one. Is there a way to modify those without forking the plugin ?

Or do you mean I should use
/javascripts/discourse/templates/components/template-name ?
(I’ve tried and it does not seems to work but I may have done some other mistake.)

Or have I misunderstood something ?

Thanks in advance !

Maybe there’s some confusion surrounding terminology here. In any case, just use:

<script type="text/x-handlebars" data-template-name="javascripts/components/template-name">

You don’t need to include anything else in the data-template-name. It will get mapped correctly.


Thanks a lot !
That’s exactly what I needed. :slight_smile:

1 Like