This project is read-only.

Example of implementing IHtmlFilter?

Topics: Customizing Orchard
Jul 5, 2013 at 9:39 PM
Edited Jul 5, 2013 at 9:44 PM
Is there an example of how I would implement IHtmlFilter to create a module that can process short codes such as [youtube:dskhfskj] so a youtube video is rendered? I already have code to do in my current apps - just need to figure out how to plug it into Orchard.

Edit: Found this by young Skywalker. Where exactly does this plug into orchard? As a module?
    public class RelativePathHtmlFilter : IHtmlFilter
        private readonly Regex _regex;
        private readonly UrlHelper _urlHelper;

        public RelativePathHtmlFilter(RequestContext requestContext)
            _regex = new Regex("\"(~/[^\"]*)\"");
            _urlHelper = new UrlHelper(requestContext);

        public string ProcessContent(string text, string flavor)
            return _regex.Replace(text, match => _urlHelper.Content(match.Groups[1].Value));
Jul 6, 2013 at 10:54 AM
Yes, create a module and create your class in there. When you launch Orchard, go to Modules and enable your feature.
Orchard will find and register all classes that implement IDependency (from which IHtmlFilter derives) and registers with the IoC container.
Jul 7, 2013 at 2:56 AM
So i dont need to implement IDependency? Just IHtmlFiler?
Jul 7, 2013 at 10:00 AM