Style.Require("NAME") not working

Topics: Writing modules
Dec 31, 2013 at 12:11 AM
Is there any situation in which Style.Require() wouldn't include (or even attempt to include) the stylesheet referenced in a custom module?

In my ResourceManifest.cs file, I have the following:
using Orchard.UI.Resources;

namespace PJS.ThemeSwitcher {
    public class ResourceManifest : IResourceManifestProvider {
        public void BuildManifests(ResourceManifestBuilder builder) {
            // Create and add a new manifest
            var manifest = builder.Add();

and in my View file, I have the following:
The script file gets included, but the style is completely ignored.

Any ideas on what/how I can test to possibly see why this is happening? Thanks for the help
Dec 31, 2013 at 12:18 AM
Even using Style.Include() with the full path doesn't work.

Could it possibly be because this shape is injected into the page using FilterProvider? Does that prevent Style.Include() and Style.Require() from working, but still allow Script.Require()?
Dec 31, 2013 at 1:59 AM
You can test by putting the line of code (with Style.Include and .Require) in Layout.cshtml for example. You can use an F12 tool of browser to make sure if a wrong file path is not referenced.

This happened to me recently and the cause was that the shape was retuned as a partial result after an AJAX call and naturally it didn't affect referenced resources. This isn't the case here as the script file is included.

Dec 31, 2013 at 2:18 AM

Style.Require("ThemeSwitcherCss"); (I changed the name)

to Layout.cshtml works actually loads the stylesheet and clicking on the path from View Source, opens up the file and I can see the code within it. appears that it's only not loading it from within my module in the shape that is being rendered from FilterProvider.

I suppose I could add the style settings inline to the shape file...just seems really odd that a Script.Require works and a Style.Require doesn't in this scenario.

Thanks for the tips on troubleshooting this. At least I know now that the path is correct and the stylesheet is able to be included.
Jan 2, 2014 at 2:58 AM
I've seen similar weird issues a while ago with resources named the same as the files they're pointing to (without extension). Try renaming/prefixing resource names with something and see if it helps.
Jan 3, 2014 at 5:49 PM
I thought that may be the case so I named the physical file themeswitcher.css and referenced it in my ResourceManifest file as ThemeSwitcherCss.

Same result with it not be included. I decided just to include it in the shape using a <link> tag for now. I'll keep working on it. My shape is named ThemeSwitcher.cshtml, so maybe I'll play around with that name as well in case it's causing a conflict.

Thanks for the tip on that =)