AddEvent code not working in Discourse

I’m trying to add some code in Discourse for an event calendar. I’ve done the four space indent but it doesn’t seem to work.

Here’s the code snippet:

This is what I get…

I’m not a regular coder, so please if you could simplify the jargon I’d be ever grateful. :pray:

1 Like

The cause here is that Discourse filters user input in posts as a security measure. You wouldn’t want random users to run scripts on your site, so we filter them out.

You can use a theme component to make this work. If you add something like this in a new theme component - under the header tab - and then add it to your active theme, you’ll be able to use that embed.

<script type="text/discourse-plugin" version="0.8">
  const  loadScript  = require("discourse/lib/load-script").default;
  const { next } = require("@ember/runloop");

    post => {
      const calendars = post.querySelectorAll(`[data-wrap="addEvent"]`);
      if (!calendars.length) return;

      calendars.forEach(calendar => {
        const wrapper = document.createElement("div");
        wrapper.dataset.calendar = calendar.dataset.calendar;
        wrapper.dataset.configure = false;

      next(() =>
    { id: "AddEvent decorator", onlyStream: true }

Once you do that, you can add the addEvent calendar to a post by adding something like this in your post.

[wrap=addEvent calendar=bJ306355][/wrap]

You can change the calendar=bJ306355 attribute to add the specific identifier for the calendar you want to embed.

The last thing you need to do is whitelist the AddEvent script in your site setting (this is another security layer).

Search for the content_security_policy_script_src in the admin and add this link there

Let me know if this works for you, and I can package it as a theme component.


Hi @Johani,

Your solution works for me. Just wanted to let you know.


1 Like

So, I just created a new theme component to render an AddEvent calendar.

:link: GitHub - graydenshand/discourse_upcoming_addevent: Replace the DiscourseEvent "upcoming events" calendar with an AddEvent embed

Instead of embedding the calendar in a post, which is too narrow to display the desktop version of the embed, this theme component hijacks the DiscourseCalendar plugin’s “Upcoming Events” page.

Note, that in order to do this, I had to customize the AddEvent script ( to allow for re-renders between page transitions.

1 Like