Embedding with multiple categories?


#1

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.


#2

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.


(Jeff Atwood) #3

Pretty sure we support this now, don’t we @eviltrout?


(Robin Ward) #4

We’ve improved this a bit. You can now choose to embed certain hosts to certain categories. Would that work for you?

Adding the category to the embed options would be insecure as they could be spoofed.


#5

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?


#6

My situation is similar to @fantapop.

If that host configuration could go down a level into the URL structure that would work for me.
For example:


(Robin Ward) #7

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:

  1. We add another configuration option which is a relationship between paths on a host and categories.

  2. 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 would require some work but are doable.


#8

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.


(Rob) #9

Would the meta tag be something that we set in the embed script? This would be really useful.


#10

What does it look like when you embed the topic id along with the embed data? Are you using a different discourseUrl in the script?

It sounds like you have something working, but I can’t conceptualize it. Would you be able to explain your setup?


#11

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;

#12

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.

Thanks for sharing this setup, @fantapop!