I’m attempting to override the main header-dropdown html tags via my custom theme.
My proof on concept was this:
<script type="text/discourse-plugin" version="0.8.23">
api.reopenWidget("header-dropdown", {
html(attrs) {
if (attrs.icon == 'bars') {
return 'TEXT TO RETURN INSTEAD OF HAMBURGER';
} else {
return this._super(attrs);
}
}
});
</script>
In this example, ‘TEXT TO RETURN INSTEAD OF HAMBURGER’ displays correctly.
Now, I want to wrap this text with a tag.
The solution seems to use the h helper like so:
return h('b', "TEXT TO RETURN INSTEAD OF HAMBURGER");
However, this returns ReferenceError: h is not defined.
Attempting to add import { h } from "virtual-dom"; doesn’t work, which makes sense because I’m in the custom theme head override. (/admin/customize/themes/7/common/head_tag/edit)
What would be the correct way to do this without creating a plugin?
My issue is that from the <head>, I don’t have acces to @computed. Is there a way to require it?
I did manage to override the controller:composer save action. However, from there I don’t have access to InputValidation to throw a custom error (I wouldn’t know how to target the correct input from there either).
<script type="text/discourse-plugin" version="0.8.23">
api.modifyClass('controller:composer', {
@computed("model.categoryId", "lastValidatedAt") //ReferenceError: computed is not defined
categoryValidation() {
console.log('categoryValidation');
this._super();
}
});
</script>
I’m not sure if this is the only way to do it, but I’ve modified computed properties in customizations like this (the example is using the availableSorts computed property):
Notice that these lines are just a re-arranging of the import lines that you see in Discourse’s codebase. So anything you can import, you should be able to require in a theme.