gar1t
(Garrett)
April 19, 2024, 4:39pm
1
I’m trying to access the api from a custom component with this snipped in the html body:
<script type="text/discourse-plugin" version="0.8">
console.log("###########", api.getCurrentUser());
</script>
This snippet however does not appear in the page HTML.
What’s the correct approach here?
Btw, this is the same question posed a few years ago but not answered:
I have tried to add custom html through jquery using plugin api events like api.onAppEvent(), api.decorateWidget(), etc…, in Edit CSS/HTML >> /head section. But, the events which i tried is not triggering the jquery on page load.
So, i am little bit confused about what event need to use. Because that event should trigger the jquery throughout the site on page load instead of blocking the scripts on particular pages.
Here is the code which i tried,
[SearchButtonIssue]
Hello Garrett!
If you put this code in your theme to theme component Head tab,
You should be able to see the output in the browser’s console (there is no HTML being displayed here):
Useful guide to learn about Theme component (also #theme-component tag)
Discourse Themes and Theme Components can be used to customize the look, feel and functionality of Discourse’s frontend. This section of the developer guides aims to provide all the reference materials you need to develop simple themes for a single site, right up to complex open-source theme components.
This introduction aims to provide a map of all the tools and APIs for theme development. If you prefer a step-by-step tutorial for theme development, jump straight to:
Themes vs. Theme Compon…
gar1t
(Garrett)
April 19, 2024, 4:58pm
3
Thank you. I had placed this code in the body section.
It’s surprising to me that the head behavior here is different. It looks like Discourse is removing these api snippets from the body section. Other script elements are retained there.