Showing the content of a pinned topic at the top of a category
-
How could I show the content of a topic I've pinned at the top of a category? I'm using the Harmony theme on my NodeBB forum, and I see that when I open a category pinned topics appear at the top, but I need to click on them to view the content. I'm a professor and I'm trying to set up a discussion for my students in such a way that when they open a category they first see my discussion prompt with some guiding comments and questions for the discussion.
Kudos to the NodeBB team for creating such amazing APIs, by the way. It has freed me from relying on my crummy LMS.
-
Instead of pinned topics you could use a html widget that is placed at the top of the category page. For example see this category https://community.nodebb.org/category/26/developer-faq. The "What is the Developer FAQ?" part is a html widget created in the ACP and placed in the header. It only shows up on that category.
If you really want to show content of pinned topics on the category page itself you will have to write some custom js code or a plugin to load that data and display it there with a custom template.
-
That's very cool! I haven't worked with NodeBB's widgets before, but it might be a little tedious to create HTML widgets for each prompt through the ACP. I'm looking for a scripted solution, as what i have in the back is a YAML file containing all of the prompts with the cids of the category to which they need to placed. Using a widget instead of a pinned post sounds great, as long as I can figure out how to script it.
-
In case any one wants the solution (it took me all day to figure it out), here is my discussion post HTML widget code, which depends upon an exposed prompts.json file generated from my YAML data:
<div id="prompt">Refresh the page if the discussion post prompt has not loaded here.</div> <script> getText("prompts.json"); const cid = {cid}; async function getText(file) { let response = await fetch(file); let data = await response.json(); let messageObj = data.find(item => item.cid === cid); let message = messageObj ? messageObj.message : 'Discussion post prompt not found. It may not be ready yet, but will be a few days before the relevant class.'; document.getElementById("prompt").innerHTML = message; } </script>
Thanks, @baris, for the pointer.
-
-
@baris said in Showing the content of a pinned topic at the top of a category:
The widget lets you put category ids in the ACP, the widget will only show up in those categories.
Ah, I had to put it in the category.tpl and not in the global one as otherwise it was also showing on the sub topics. Got it!