Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
712 views
in Technique[技术] by (71.8m points)

asp.net - How to locate resources in Orchard

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?

I've had a look at ResourceManifest files, using builder.Add.DefineResource but I can't seem to find it's counterpart in the view. Or do I just put the full path in?

Any hints?

Cheers Carl

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you need to define the new resource (script or stylesheet):

  1. Create a class inheriting IResourceManifestProvider
  2. Provide the void BuildManifests(ResourceManifestBuilder builder) method and
  3. Add all necessary resources via builder.Add().DefineStyle("") or builder.Add().DefineScript(...), just as you noted in your question.

For example:

public class ResourceManifest : IResourceManifestProvider {
    public void BuildManifests(ResourceManifestBuilder builder) {
        var manifest = builder.Add();
        manifest.DefineStyle("MyStyle").SetUrl("mystyle.css");
        manifest.DefineScript("MyScript").SetUrl("myscript.js").SetDependencies("jQuery");
    }
}

This defines one style and script you can reuse in your views. Urls are relative to /Styles (or /Scripts) folders in your theme/module where the class is located.

If you want to reuse some of resources already defined (in all enabled modules and themes), it's as easy as writing eg.:

...
@{
    Style.Require("MyStyle").AtHead();
    Script.Require("MyScript").AtFoot();
}
...

inside your .cshtml view file. Example above would inject mystyle.css and myscript.js at appropriate locations (header/footer of the final page).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...