Layer Rules on Chapters/Sub Pages?

Topics: Customizing Orchard, Troubleshooting
Mar 23, 2011 at 1:13 AM

Just started working on Orchard for a pretty large client, and have a pretty decent understanding of the UI Layer of Orchard. 

I have a setup where I have Chapters, ie:

  1. Release
    1. screen-shots
    2. testing
    3. ...

The URLs to the sub-pages look like:


When creating a new Layer, I added a layer rule:


So that all pages in the screen shot category could have a different layout, but it doesn't seem to work on anything by a ROOT page, ie /release-1/. 

Any suggestions? -- The goal here is to have Books with Chapters that all have similiar Chapter layouts.  They will all have screen-shots, etc. and should all have the same layout.



Mar 23, 2011 at 3:11 AM

My module:

Gives you a Part that allows you to pick different layouts from a drop-down list when you're editing content.


Shows you how to override the layout for all content items of a particular type.

Mar 23, 2011 at 5:04 AM

For the widgets, you'd have to build your own rule, based on the code from url, but allowing for the string to be anywhere, something like urlContains(str). The built-in url rule only supports wildcards at the end.

Mar 24, 2011 at 5:43 PM

@pete --> Thanks man, I think this will work, but I do have another N00b question...  How do I define a layout?  The only thing I see in the dropdown is "Default", so there must be someplace (Themes.txt?) where this is setup....



Mar 24, 2011 at 6:01 PM

Hi Stu, I've now posted brief documentation at .

Basically you need to inherit from ILayoutAlternatesProvider by referencing my project. Then you can yield return as many names as you like.

The next version of the module will allow you to type in additional layout names in the part settings, to make things easier. However the programmatic interface is nice if you want to release your theme and have the layout options automatically populated.


Mar 24, 2011 at 7:36 PM
Edited Mar 24, 2011 at 7:37 PM

So this is frustrating...

I had to resinstall my Orchard project after a fatal build.  I installed your module, but now none of the dropdowns appear.  It's enabled, and there are plenty of Layout-{item}s in the theme directory... 

What's going on now?


-- Never mind... read your cdocumentation and now it all makes sense... ;)


Mar 24, 2011 at 7:51 PM
Edited Mar 24, 2011 at 10:17 PM

Never Mind... figured out what was going wrong there... 

So Assume that I;m not a C# Dev.  When you say

"In your theme or module, add a reference to the "Downplay.Orchard.LayoutSelector" project"

Where do you add that reference?

I've got the class file set up in my myTheme/Services/LayoutAlternativesProvider.cs file...




--EDIT-- N00b -- could not find the reference, so edited your Module in the LayoutSelectorService.cs to allow for my list of layouts.  Works great.

Mar 25, 2011 at 1:06 PM
Edited Mar 25, 2011 at 1:07 PM

No problem - you could also edit the DefaultLayoutAlternatesProvider.cs to supplement the existing "Default". The only problem with doing it that way / your way, is that if you update to a new version of the module your changes will get overwritten!

For future reference if you need it, here's how you implement ILayoutAlternatesProvider:

1. Add the module project properly to your solution by right-clicking on the solution, Add > Existing Project ... and select the Downplay.Orchard.LayoutSelector.csproj from Modules/Downplay.Orchard.LayoutSelector within your website.

2. Right-click the "References" node in Solution Explorer, from your theme (or website if your theme isn't in its own solutio). Select "Add Reference". Go to the "Projects" tab and select Downplay.Orchard.LayoutSelector.

3. You can now create your own LayoutAlternatesProvider.cs as the following (note I my convention is "Alternates" not "Alternatives", this is just the Orchard code convention in the shaping bits):


public class LayoutAlternatesProvider : ILayoutAlternatesProvider {




4. Click on "ILayoutAlternatesProvider", you should see a small lightning bolt icon appear. Click on that, and select "using Downplay.Orchard.LayoutSelector.Services". This will add the correct "using" reference to the class file.

5. Click on "ILayoutAlternatesProvider". You should again see the lightning bolt. Click on it again and select "Implement interface ILayoutAlternatesProvider". This automatically creates the appropriate method stub(s) for an interface.

6. Delete the line that says "throw new NotImplementedException();". Replace it with the following:

yield return "MyLayoutName1";

yield return "MyLayoutName2";

And so on as many times as you want. These are the values that get added to the drop-down.

Anyways, glad you found it useful! Like I say the next release will have the slightly more designer-oriented configuration of being able to just add names in the UI :)

Mar 25, 2011 at 4:28 PM

This is perfect... Thanks again Pete.  Now on to the next thing... Creating custom fields for each layout per chapter...