This discussion is about embedding Discourse into another site with multiple categories. Currently, Discourse only allows a single category to be selected for all embeds. Users JamesChevalier and fantapop are seeking a way to use multiple categories for multiple embeds.
According to eviltrout, Discourse has improved the embedding feature to allow choosing certain hosts to certain categories. However, this does not meet the needs of JamesChevalier and fantapop, who want to map URLs to specific categories.
Adding a configuration option to specify a relationship between paths on a host and categories.
Embedding a meta tag in the source document that specifies the category, which Discourse can read when crawling the document.
Both solutions are considered doable, with fantapop suggesting that option 2 might be easier to use and fit better into the current embed UX.
Fantapop shares their current setup, which involves passing a topic ID along with the embed data. JamesChevalier finds this helpful and discovers that specifying a topicId is a feature mentioned in this post.
The current method of embedding discourse into another site requires a single category be selected for all embeds. This is done in Admin → Embedding, by setting the embed category value.
Are there plans to allow multiple categories be used for multiple embeds, or is there a way to do that currently?
The scenario I have is a single host/site (not WordPress) that I’d like to embed Discourse in, which has a few separate sections. The comments within each section in that site should go to different categories within the Discourse site.
I’m also interested in this functionality. Did you ever find a way? It seems like passing a category Id along with the embed request would be a reasonable option.
In this case, We have different sections on a site hosted with the same subdomain (in this case www). It would be nice if comments on a new blog post would open a new Blog Comments category topic and new comments on a bundle would open a new Bundle category topic. We’re able to work around the issue manually by creating topic ahead of time for each Bundle and then passing the topic id along with the embed data.
Would it still be insecure if the category had to pre-exist and if the embed config specified a list of categories each domain would work for?
At that point the worst that could happen is a user creates something in the wrong category. It’s not a security hole but it’s still annoying if your users can troll you that way.
It sounds like there are two ways I could solve this:
We add another configuration option which is a relationship between paths on a host and categories.
We embed something in the source document that specifies the category. For example a meta tag. When discourse crawls the document it sees the category in the meta and places it there.
Both of those sound like reasonable options. Option 2 sounds a little easier to use and that it might fit into the current embed UX a little better than option 1. Thanks for your time.
We end up passing the same discourseUrl which is the instance of discourse. Then we pass either a discourseEmbedUrl or a topicId along depending on which section of the site the comments will be going in. The topic id is added to the dom during page render if it already exists.
Here is a code snippet
var TOPIC_ID_ATTR = 'data-discourse-topic-id';
var shareUrl = $('meta[property="og:url"]').attr('content'),
topicId = $('[' + TOPIC_ID_ATTR + ']');
var embedConfig = {
discourseUrl: <forumUrl>
};
if (topicId.length > 0) {
embedConfig.topicId = parseInt(topicId.attr(TOPIC_ID_ATTR));
}
else {
embedConfig.discourseEmbedUrl = shareUrl;
}
window.DiscourseEmbed = embedConfig;
Woah, I didn’t know you could specify a topicId like that. I went hunting around and found this post which covers it, if anyone else is interested in further details.