Override Body in Module

Topics: Troubleshooting, Writing modules, Writing themes
Mar 16, 2011 at 12:19 AM

Hi there Orchard folks,

I'm trying to create an Image Rotator module to display those sliding splash pages you find so often on home pages. I'm trying to wrap this: http://cssglobe.com/lab/easyslider1.7/01.html

If you view source of that link, you'll see that the slider operates over a UL of Linked Images wrapped in a div:


<div id="slider">
      <a href="/30">
        <img src="images/01.jpg" alt="Css Template Preview" />
      <a href="/7">
        <img src="images/02.jpg" alt="Css Template Preview" />


Pretty straigtforward.

My module design aims to capture a few of the variables that control the image effects (duration, infinite loop, etc) in an ImageRotatorPart. I planned to compose that part with a Body where the author would have to create that UL of linked images:


ContentDefinitionManager.AlterPartDefinition("ImageRotatorPart", builder => builder.Attachable());
    cfg => cfg
        .WithSetting("Stereotype", "Widget")


What I can't figure out is how to take over rendering of the body so that I can give the wrapping DIV an ID and initialize it from JS.

I tried overriding the Parts.Common.Body.cshtml, which almost works, but it applies to all of the Bodies present on the page.

I tried adding the Body to the Shape, and then I can access it from my Part template...but then it renders once from my template and a second time from what I can only assume is magic.


public string Body {
    get { return this.As<BodyPart>().Text; }
    set { this.As<BodyPart>().Text = value; }

I'm sure there's a simple way to do this, but this is my first foray into modules. Thanks for the help!

Travis Pettijohn


Mar 16, 2011 at 12:26 AM

It's the other way around: create your own shape from the driver of the part and give default positioning into the content zone using a placement.info file. This way, people will be able to override your defaults and template very easily from their themes. You do not want to take over body.

Mar 16, 2011 at 6:13 AM

Is there an example you can point me to where a Content Part subsumes Body like this? The docs for shapes only go over the very basic Map part with Latitude and Longitude, so I'm sure I'm missing something. 

Mar 16, 2011 at 6:17 AM

No, I don't have an example because what I'm saying is that you shouldn't. :)

There are plenty of examples of shapes being added to content zones (pretty much all of the content parts work this way).

Making sense?

Mar 16, 2011 at 4:37 PM

Yeah it is. A content part's view has to be able to be overrideable at higher levels, so you necessarily can't override it at a lower level.

Good good...some refactoring and now my ImageRotator is working. Now I want to add it to the Content zone and have it render before the body.

    <Place Parts_ImageRotator="Content:1.0" />
    <Place Parts_Common_Body="Content:2.0" />

Nothing I do seems to put ImageRotator before Body. I can hide the body by setting its value to "-", but Content:before, Content:after... can't figure it out. Is something different because it's in a widget?

Mar 20, 2011 at 3:20 AM

Strange, I just tried it and "Content:before.1" worked for me.