I have something like this in my JS tab of my theme:
import { apiInitializer } from "discourse/lib/api";
export default apiInitializer("0.11.1", (api) => {
api.renderInOutlet("above-main-container",
<template>
<div>
html stuff
</div>
</template>
);
});
I copy pasted that, it works (just an example)
How do I make this render only on the home page or only on the categories page
sorry if this is not a good question
It’s a good question, don’t worry about it! This will work:
import Component from "@glimmer/component";
import { service } from "@ember/service";
import { apiInitializer } from "discourse/lib/api";
import { defaultHomepage } from "discourse/lib/utilities";
class HomepageOnly extends Component {
@service router;
get shouldShow() {
return this.router.currentRouteName === `discovery.${defaultHomepage()}`;
}
<template>
{{#if this.shouldShow}}
<div>
html stuff
</div>
{{/if}}
</template>
}
export default apiInitializer((api) => {
api.renderInOutlet("above-main-container", HomepageOnly);
});
This creates a new component, which uses the router service and defaultHomepage utility to check if you’re on the homepage. Then the component is rendered in the outlet.
There’s a little more here: Add custom content that only appears on your homepage
Thank you Kris, that works perfectly. Thanks for the link as well, trying to learn.