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]
2 Likes
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)
So, you want to create Discourse themes? Not sure where to start? Or maybe you have created Discourse themes before, but want to learn how to do even more cool things. Well, you’ve come to the right place
Developer’s guide to Discourse Themes
Subjects include a general overview of Discourse themes, creating and sharing Discourse themes, theme development examples, searching for and finding information / examples in the Discourse repository, and best practices.
Prerequisites:
…
1 Like
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.
2 Likes
system
(system)
Closed
May 19, 2024, 4:59pm
4
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.