Module - FilterProvider/IResultFilter + Module/Scripts

Oct 16, 2010 at 5:21 PM
Edited Oct 16, 2010 at 5:24 PM

Sorry for the cryptic title. I'm building a custom module which needs to register few css and script file links. Those scripts and styles are under MyModule\Scripts and MyModule\Styles - folders. When registering those files I'm using following code:


model.Zones.AddAction("head:scripts", html =>
                _resourceManager.RegisterHeadScript("shCore.js", html);

It does add the reference to the page but the path for the file is wrong. Is there a method to get the root path of a module? Or do I need to use full path to the module to add the references. Also I think the way I'm registering the scripts/styles seems bit "wrong". Should I use the Writer instead to write the script/css references? Problem with IResourceManager.RegisterHeadScript is that it needs a reference to HtmlHelper and I could not think any better way of filling out that need.


Oct 16, 2010 at 5:38 PM

There is a brand new Resource Manager which handles all scenarios. I would suggest you to use this one, because the syntax you are using will no more be supported. Could you tru using the dev branch and take a look at what you would have to change to move to this version ?

Oct 17, 2010 at 6:41 AM

Here is the revelant code:

public void OnResultExecuting(ResultExecutingContext filterContext)
            var model = BaseViewModel.From(filterContext.Result);
            if (model == null)

            model.Zones.AddAction("head:scripts", html =>
                _resourceManager.RegisterHeadScript("shCore.js", html);

I'm doing this against the latest dev branch. Well a fork really but I have gotten the latest checkins from dev branch few moments ago.

This is the resource manager I'm using:

public interface IResourceManager : IDependency {
        void RegisterMeta(string name, string content);
        FileRegistrationContext RegisterStyle(string fileName, HtmlHelper html);
        FileRegistrationContext RegisterStyle(string fileName, HtmlHelper html, string position);
        void RegisterLink(LinkEntry entry, HtmlHelper html);
        FileRegistrationContext RegisterHeadScript(string fileName, HtmlHelper html);
        FileRegistrationContext RegisterHeadScript(string fileName, HtmlHelper html, string position);
        FileRegistrationContext RegisterFootScript(string fileName, HtmlHelper html);
        FileRegistrationContext RegisterFootScript(string fileName, HtmlHelper html, string position);
        MvcHtmlString GetMetas();
        MvcHtmlString GetStyles();
        MvcHtmlString GetLinks(HtmlHelper html);
        MvcHtmlString GetHeadScripts();
        MvcHtmlString GetFootScripts();
Does that look like latest one or did I fault while trying to get it? If you can push me to something similar in Orchard source I can probably figure it out. Only filter I could find which is doing a similar thing to what I'm trying is ResourceFilter. 


Oct 17, 2010 at 6:56 AM

Sorry about that. I just noticed that clearly I wasn't using the latest version from dev branch. Forgot to click the update button in TortoiseHg. Should be moving back to using Hg from command line :d

Oct 17, 2010 at 8:53 AM

So after I got the actual latest version everything went along very fast. I have now a basic SyntaxHighlighter - module up and working with the latest dev branch. I'll clean it up and commit it to the fork I created if someone wants to take a look at it.