How to override the site-header.hbs file from custom theme?

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>

I also tried multiple variations:

<script type="text/x-handlebars" data-template-name="components/sections/organisms/site-header">
<div>test</div>
</script>

<script type="text/x-handlebars" data-template-name="javascripts/components/sections/organisms/site-header">
<div>test</div>
</script>

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

<script type="text/x-handlebars" data-template-name="javascripts/components/sections/organisms/site-header">
<div>test</div>
</script>

but nothing helps. Could you help me please?

1 Like

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?

2 Likes

@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?

Plugin outlets are updated in themes. See Using Plugin Outlet Connectors from a Theme or Plugin

Yes. What are you trying to do?

4 Likes

@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.

You shouldn’t need to override the hbs to do any of that.

Maybe have a look at Custom Header Links

You can hide the logo with css.

New Topic Header Button adds a button

See also Plugin outlet locations theme component

3 Likes

@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?

That is not supported. Did you read my link I shared with you after your prior (duplicate?) post?

4 Likes

@merefield Yes, I read your article. I just wanted to ensure.
Okay, thanks a lot.

2 Likes

This might help (and ensure your customisations stand the test of time)

4 Likes

This theme-component might also be a consideration if your looking for header menu with dropdown submenu

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.

3 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.