This project is read-only.

Content, Media Item, AutoRoute & IShapeTableProvider: Wrapping media in a friendly route

Topics: Customizing Orchard, Writing themes
Jan 12, 2015 at 10:35 AM

I have an Orchard 1.7.3 system whereby we have a custom content type which contains a media picker field relating to a newsletter (PDF). The custom content type defines the date of the newsletter along with the applicable department.

I have assigned an auto route to the custom content type (simplified e.g. /dept/{DeptAlias}/news/{yyyy}/{mm} ) using token providers which, when requested, should then output the actual media (PDF) assigned to the content type. I cant assign the route to the actual media content as it is the department and date defined on the custom content type which classifies the PDF. The routing is working but shows the output of the custom content type which is to be expected.

I now need to amend that so that it outputs the media file instead. I have tried using the following shape provider to use a different layout thinking that might be an approach, but I am unable to determine the content type when using "Layout" as the shape type, as c.Shape.ContentItem in the following is not defined on the shape:
        public void Discover(ShapeTableBuilder builder)
                   .OnDisplaying(c =>
                           if (c.Shape.ContentItem.ContentType == "Newsletter")
If I change it to builder.Describe("Content") then the content item is populated, but the output then still loads the main Layout template and then uses the Layout-Newsletter template for the content section only.

So the question is whether am I going about things properly here? Even if I am able get the correct template to load, will I be able to output the media file from that template or will it be limited to HTML output?

It feels like I am either doing this incorrectly, or that I am just missing the final piece to get it working...

Any assistance greatly appreciated!