I’m trying to make a plugin which will change header into something like this
It doesn’t really matter how does it look, that matters is I don’t want to use customisation on /admin/customize/css_html
path. I want to make a plugin which will magically change everything I need.
That I found so far is, there is no template for the header, it renders via virtual-dom.
The way it renders is following:
-
assets/javascripts/discourse/templates/application.hbs
template, which can be overloaded, renderssite-header
component.{{plugin-outlet “above-site-header”}}
{{site-header canSignUp=canSignUp
showCreateAccount=“showCreateAccount”
showLogin=“showLogin”
showKeyboard=“showKeyboardShortcutsHelp”
toggleMobileView=“toggleMobileView”
toggleAnonymous=“toggleAnonymous”
logout=“logout”}}
{{plugin-outlet “below-site-header”}} -
assets/javascripts/discourse/components/site-header.js.es6
component extends and returnsheader
widget.const SiteHeaderComponent = MountWidget.extend(Docking, {
widget: ‘header’,
…
});export default SiteHeaderComponent;
-
assets/javascripts/discourse/widgets/header.js.es6
widget generates virtual-dom for the header.export default createWidget(‘header’, {
tagName: ‘header.d-header.clearfix’,html(attrs, state) {}
});
My thoughts
I can create my own widget my-header
which will extend existing header
, there I’ll just update html. I don’t want to copy-paste anything into it, I want just to override html()
method.
/plugins/discourse-foo/assets/javascripts/discourse/widgets/my-header.js.es6
Then I can create my own my-site-header
component which will extend existing site-header
with just overriding it to point into my-header
widget.
/plugins/discourse-foo/assets/javascripts/discourse/components/my-site-header.js.es6
Then I override application
template to show my-site-header
component instead of site-header
/plugins/discourse-foo/assets/javascripts/discourse/templates/application.hbs
{{plugin-outlet "above-site-header"}}
{{my-site-header canSignUp=canSignUp
showCreateAccount="showCreateAccount"
showLogin="showLogin"
showKeyboard="showKeyboardShortcutsHelp"
toggleMobileView="toggleMobileView"
toggleAnonymous="toggleAnonymous"
logout="logout"}}
{{plugin-outlet "below-site-header"}}
The question is, how can I extend all of these components and widgets? Can you please point me to the right way of doing that? Thanks.