Raj
Raj

Reputation: 31

How to include style sheets and js files inthe view of Orchard cms

How to include style sheets and js files inthe view of Orchard cms, Failed to load resource: the server responded with a status of 404 (Not Found)

Upvotes: 0

Views: 4410

Answers (2)

Bertrand Le Roy
Bertrand Le Roy

Reputation: 17814

You may also use Script.Include and Style.Include if you don't want to create a manifest but want to reference the files directly but still eliminating doubles.

The 404 here is very probably due to your failing to include a web.config file that allows the serving of the file. You can copy the one from one of the existing script directories.

Upvotes: 5

Giscard Biamby
Giscard Biamby

Reputation: 4619

  1. Create a ResourceManifest.cs file in your Theme or Module.

    using Orchard.UI.Resources;
    namespace MyNameSpace {
        public class ResourceManifest : IResourceManifestProvider {
    
            public void BuildManifests(ResourceManifestBuilder builder) {
                var manifest = builder.Add();
                manifest.DefineStyle("MyScriptName").SetUrl("~/Modules/MyModule/Scripts/scripts.js");
                manifest.DefineScript("MyStyleName").SetUrl("~/Themes/MyTheme/Styles/site.css");
            }
        }
    }
    

In your view, include the script and style like this:

    @{
        Style.Require("MyStyleName");
    }

    @using(Script.Foot()) {
        Script.Require("MyScriptName");
    }

You can also use Script.Head() to put the .js include in the <head> tag.

Upvotes: 6

Related Questions