How to add shortcode support to Orchard?

Topics: Customizing Orchard
Mar 6, 2013 at 2:36 PM
Where would I hook into Orchard so as to add short code support? For example, if i want to embed a youtube video i would like to type [youtube:youtube_string]. I have code that will does in my own applications. How would i hook into Orchard to add this?
Mar 6, 2013 at 2:41 PM
If you implement IHtmlFilter, you will be able to process these short codes.
Feb 23, 2014 at 9:29 AM
Is there any examples how to to this sipke?
Feb 23, 2014 at 10:03 AM
Sure, IHtmlFilter is used in several places in Orchard. It has a single member (string ProcessContent(string text, string flavor)), so it's really easy to implement. All you need to do is to take the passed text, run your (existing) code over it and return the result.

E. g. Markdown is processed like this:
namespace Markdown.Services {
    public class MarkdownFilter : IHtmlFilter {
        public string ProcessContent(string text, string flavor) {
            return String.Equals(flavor, "markdown", StringComparison.OrdinalIgnoreCase) ? MarkdownReplace(text) : text;

        private static string MarkdownReplace(string text) {
            if (string.IsNullOrEmpty(text))
                return string.Empty;

            var markdown = new MarkdownSharp.Markdown();
            return markdown.Transform(text);
Feb 23, 2014 at 6:06 PM
Thanks Jasper. really cool. I will try this out.
Can we extend markdown with for example [one_third]Content[/one_third]. This would return <div class="span4>Content</div>
If not, are there any third party libraries for this?
Feb 23, 2014 at 9:22 PM
Interesting idea... maybe you could have short codes, that actually render dynamic shapes inline. hmmm