Originally posted at: drewbrasher.com/blog/content-warning-module
Sometimes we may want to create some content that some people might not want to see. For example we might want to talk about a movie and say things that would be a spoiler to someone who hasn't watched it yet or we might want to talk about something or post an image that could cause emotional distress to some people.
A common way that social and messaging platforms accommodate for this is to allow people to set some content as hidden and instead show a warning until the person looking at it indicates that they want to see it.
My personal website (drewbrasher.com) is built on the open source Orchard Core CMS so I decided to write an Orchard Core CMS Module that allows you to put a content warning around some content so that users can decide if they want to see it or not. The module allows you to put a content warning on some inline content inside a MarkdownBody or HtmlBody using a Shortcode or you can add the Content Warning Part to a Content Type to allow you to put a warning on the whole Content Item.
To use the shortcode, you can select it from the Shortcodes menu in the editor toolbar like this:
or you can enter the Shortcode directly into the editor like this:
[content_warning 'Spoiler for The Matrix']Trinity was a famous hacker before being freed from the matrix. [/content_warning]
or the shortened alternative syntax:
[cw 'Spoiler for The Matrix']Trinity was a famous hacker before being freed from the matrix. [/cw]
Here is what it would look like:
To put a warning on an entire content item, like a whole blog post, you would first need to add the Content Warning Part to your Content Type definition. Once you have done that, you can add a content warning to any item of that content type by checking the "Show Warning" box and entering the warning message you want to display to users.
If you have an Orchard Core CMS site you would like to add this feature to, you just need to add the DrewBrasher.OrchardCore.ContentWarning nuget package to your project and enable the "Content Warning" feature.
You can check out the source code for this module in the github.com/DrewBrasher/OrchardCoreModules Repository.
I am excited to be doing a demo of this module at Orchard Harvest 2024 (orchardcore.net/harvest) and I hope to see you there!
The JavaScript and CSS in this module are based on the Considering content warnings in HTML blog post by Aaron Gustafson.
Top comments (0)