This project is read-only.

Add a stylesheet to the head from a module when the module is enabled.

Topics: Customizing Orchard, Writing modules
Jun 30, 2014 at 10:40 PM
Edited Jun 30, 2014 at 10:46 PM
These are just my notes on adding linked resources to the head from a module. Two modules that do this:

  • ShapeTracingWrapper.cshtml
  • Style.Include("...")
  • ShapeTracingFactory.Created
  • var shapeMetadata = (ShapeMetadata)context.Shape.Metadata;
  • shapeMetadata.Wrappers.Add("ShapeTracingWrapper");
  • What are wrappers?
  • Why do we only add a wrapper to certain ShapeTypes?
  • CombinedResourceManager
  • Overrides the default ResourceManager
  • What if two modules override the ResourceManager?
  • Using the shapeMetadata.Wrappers.Add() method, to inject some JavaScript, lets me use jQuery to inject a style sheet and also control the order of the style sheets.
Jul 3, 2014 at 7:35 PM
You may be interested in (contributing to as well ;-)) to this:

Both mentioned modules really do a lot more than just adding scripts so the techniques they use are not the best way if you just want that. You could simply write a result filter for example and use an injected IResourceManager to include a stylesheet.
Jul 4, 2014 at 9:29 PM
Edited Jul 4, 2014 at 9:29 PM
Nice list of examples. That might be helpful down the road. Thanks.

I'm not sure what you mean by using an injected IResourceManager, because my understanding is that we cannot add content to the head from there. In any case, the solution that I chose stemmed from the way Shape Tracing does it, as follows:

    // The purpose of this wrapper is simply to add JavaScript and CSS.

    public class DesignerFactory : IShapeFactoryEvents, IShapeDisplayEvents
        // ctor and other required interface methods omitted for clarity

        public void Created(ShapeCreatedContext context)