Is it possible to insert an H2 heading in the tags area? The H2 heading should be the name of the tag.
I can’t use the tags banner component because the h2 is not on the side of the right sidebar, it’s above.
Is it possible to insert an H2 heading in the tags area? The H2 heading should be the name of the tag.
I can’t use the tags banner component because the h2 is not on the side of the right sidebar, it’s above.
Write some code to achieve what you need. Here I have written a simple solution for you. Try it, it should do what you want
<script type="text/x-handlebars" data-template-name="/connectors/discovery-list-controls-above/tag-h2">
<h2>
{{#if h2_tag}}
{{h2_tag}}
{{/if}}
</h2>
</script>
<script type="text/discourse-plugin" version="0.8">
api.registerConnectorClass("discovery-list-controls-above", "tag-h2", {
setupComponent(args, component) {
if (window.location.pathname?.startsWith("/tag/"))
component.set("h2_tag", /\/tag\/([^?]+)/.exec(decodeURI(window.location.pathname)).at(1));
},
});
</script>
Oh thank you very much!! It’s working for the first tag I click on but if I change to another tag the h2 does not change.
Oh sorry this is my problem. I made some adjustments for this
<script type="text/x-handlebars" data-template-name="/connectors/discovery-list-controls-above/tag-h2">
<h2>
{{#if h2_tag}}
{{h2_tag}}
{{/if}}
{{log this}}
</h2>
</script>
<script type="text/discourse-plugin" version="0.8">
api.registerConnectorClass("discovery-list-controls-above", "tag-h2", {
setupComponent(args, component) {
function getTagNameFromURL(url) {
return /\/tag\/([^?]+)/.exec(decodeURI(url)).at(1)
}
if (window.location.pathname?.startsWith("/tag/"))
component.set("h2_tag", getTagNameFromURL(window.location.pathname));
api.onPageChange(url => component.set("h2_tag", getTagNameFromURL(url)))
},
});
</script>