How to locate resources in Orchard

后端 未结 5 1562
梦毁少年i
梦毁少年i 2020-12-19 07:52

I am writing an Orchard theme, and I\'d like to be able to locate some of the resources packaged with the theme (images/swfs etc).

What is the best way of doing this

5条回答
  •  旧时难觅i
    2020-12-19 08:10

    Just to be clear, there are a few methods depending on your situation. I'll outline the most common I know.

    First of all, there is the inclusion of an external script or stylesheet on your particular part or theme. The standard syntax within a Razor template is this:

    @Style.Include("YourPartEdit")
    @Script.Require("jQuery")
    @Script.Include("YourPartEdit")
    

    The include files will look for that particular resource in the corresponding Style or Scripts folder: for @Script.Include("YourPartEdit"), it will look in the scripts folder for YourPartEdit.js.

    You might have noticed that with Script.Require you can register a library with Orchard (in this case the registered one is jQuery), and cause a module to require that particular script.

    To do this you create your own implementation of the IResourceManifestProvider interface, and implement the BuildManifests(ResourceManifestBuilder builder) method and create a named resource. You can use .AtFoot() or .AtHead() to even target where it will go.

    Now say you want to reference a particular image, and you want to use Razor to always point to the correct image Url. First of all I recommend placing the image in your Content folder for your theme (assuming this is a theme related image), and you'll do something along these lines:

    
    

    Now, say this is on your Layout.cshtml page - you'll now successfully serve the image anywhere on the site.

    These particular techniques should account for a multitude of situations.

提交回复
热议问题