A user, aslangm, is trying to override the site-header.hbs file from a custom theme in Discourse. They attempted to do this by adding a script to their theme’s head_tag.html file, but were unsuccessful.
pfaffman suggested that overriding templates can be fragile and recommended using plugin outlets instead. aslangm explained that they need to keep customizations within the theme, not in plugins.
pfaffman provided a link to a topic on plugin outlet connectors and asked aslangm to explain what they are trying to achieve. aslangm wants to remove the logo display, add a custom button, and display dynamic links above the header.
pfaffman provided links to topics on custom header links, hiding the logo with CSS, and adding a button to the topic header. aslangm asked if it’s possible to customize site-header.hbs through a custom theme.
merefield stated that customizing templates through a theme is not supported and provided a link to a topic on overriding templates from a plugin. merefield also shared a link to a topic on upcoming header changes and preparing themes and plugins.
Heliosurge suggested using a #theme-component for a header menu with dropdown submenu, which may be a more maintainable solution.
I’m trying to override site-header.hbs in my custom theme. The path in Discourse to that file is plugins/styleguide/assets/javascripts/discourse/components/sections/organisms/site-header.hbs.
I tried to add in my theme’s head_tag.html file:
<script type="text/x-handlebars" data-template-name="javascripts/components/sections/organisms/site-header">
<StyleguideExample @title="site header - in topic - scrolled">
<div class="d-header-wrap">
test
</div>
</StyleguideExample>
</script>
You’re trying to do something else for which you think overriding the template is the solution. Overriding templates is fragile and likely to cause issues down the road. What is it that you’re trying to do to the header that you can’t do with a plugin outlet?
@pfaffman thanks for your answer.
The main issue is that I need to keep all customizations in the theme and not in plugins. Is there another safer way to achieve this using the custom theme?
@pfaffman I want to remove the logo display, add a custom button. And above the header I want to display dynamic links which will come from a custom component.
@pfaffman thanks you. I totally understand your suggestions. However, I would like to know if there is a way to customize files, such as site-header.hbs through a custom theme. Does it make sense?
Benefit of using an existing component (especially if official or from one of the partners) is that it will likely maintained with less chances of breakage.