Overriding built-in templates (and stylesheets)


(Ionuț Staicu) #1

Continuing the discussion from How can I customize the registration form?:

Hey guys.

I was thinking about this: it is possible to override a built in template completely?

E.g. Let’s say we have app\assets\javascripts\discourse\templates\modal\login.hbs, which is builtin and I want to have myplugin\templates\modal\login.hbs, that will override the first one on build process.

Same question is also for stylesheets.

Thanks!


Why can't I modify the topic list template?
(Evgeny) #2

I think it can be done in the plugin to duplicate it.


(Rafael dos Santos Silva) #3

Yes, and we have dedicated #howto topics on this: How to customize Discourse templates

This is very easy, and pretty powerful when you want to do something that isn’t possible with just CSS. But, as with any customization, this will bring some maintenance burden. On every update you need to check if the original template had a change and adjust accordingly. So I don’t recommend for this for every user, like the OP from the linked discussion.

CSS is cascading so no need for this, just write your custom CSS and it will override original styles.


(Evgeny) #4

I’m sorry. I have a question about speed. Is there a difference in the performance of these two methods.

1. Option (css/html)

<script type='text/x-handlebars' data-template-name='list/topic-list-item.raw'>
  modified contents of list/topic-list-item.raw.hbs file goes here
</script>

2. Option

Replacing the file itself (say in the plugin)

topic-list-item.raw.hbs

Which option works faster, is there any data?


(Rafael dos Santos Silva) #5

Well the HBS override on the header will make first page load 156 bytes heavier :smile:

This is certainly negligible. There are a few WAY more important points in place here.

Like using a customization being a faster workflow, and being available on any hosted service. While the plugin will allow you to apply the same customization to many different instances easily, give you source control, etc.


(Ionuț Staicu) #6

Oh, i totally missed that! Thanks!

Yeah, but sometimes there is a lot to reset to default which I’d rather avoid :smile: