Embedding in Discourse

When embedding in discourse I cant for the life of me get it to auto assign to a category.

Im using a vueJs APP which on each standard (subcategory in discourse) I want to display embedded discussion connected to these subcategories.

My embedded code is as follows:

window.DiscourseEmbed = {
discourseUrl: ‘https://forum.example.example.nz/’,
discourseEmbedUrl: ‘https://example.example.example.nz/c/english-level-1/1-1-written-text-study/
// topicId: 273

    (function () {
      const d = document.createElement('script'); d.type = 'text/javascript'; d.async = true;
      d.src = `${DiscourseEmbed.discourseUrl}javascripts/embed.js`;

      (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(d);

I understand that using this embedded feature will create a new topic
I also cant add a category to the “window.DiscourseEmbed” object for auto assigning

But I would love to be able to have the embedded code create this new discussion in my
(category) english level 1 -> (subcategory) standard 1.1.

you can see here:

It has a link to the category I wish it to be in. But this topic is sitting in the very top level under latest which is not ideal

I know you can use the host and I have tried to hack around with this:

Im not sure if im missing the point or if I am just straight up trying to use this embedded feature for a way more specific use case than what its designed for.

Any help would be appreciated thanks :slight_smile:

1 Like

The topics should get created in the category that you set for the host. From your second screenshot, it looks like the problem is that you have setup two allowed hosts for localhost:8082, but the Path Whitelist of the first host is going to cause all topics to be published as uncategorized.

The Path Whitelist needs to be set as a path of the domain you have set in the Allowed Hosts field, so it should start with just /. Here’s a screenshot of the settings from my test site. It publishes all topics from my blog to the ‘scratch’ category:

If I wanted to only publish topics from the /blog path on my site, I would configure it like this:

I ran into an issue yesterday with posts being published to the uncategorized category of my site when I had set a category for the host. I think the cause of that was that I was trying to publish the topics to a protected category. I’m going to look into that some more to confirm whether or not that was the problem.


I followed your advice as you can see:

It is setup like you suggest. But it is still creating an uncategorized topic, and I would expect it to be in english Level 1 (category) -> 1.1 written text study (sub-category)

This is the URL i am using as discourseEmbedUrl: “h ttps://forum.studyit.govt.nz/c/english-level-1/1-1-written-text-study”

Im sure its my path Whitelist that is wrong, but it seems to dislike anything other than /.*

Lastly: the URl that the page is embedded on is : http://localhost:8082/#/English/level/1/standard/1.1/discussion

1 Like

The Path Whitelist setting should be the path to the posts that you are trying to pull into your Discourse site, not the path to where you want to publish the posts on Discourse. The way you have it setup in your second screenshot looks correct to me. I’m not sure why this would be failing to publish topics to the correct category. Do you have any security permissions set on that category? Is the group ‘everyone’ allowed to ‘Create / Reply / See’ in that category?

1 Like