This project is read-only.

alternate layout for branding area

Topics: Customizing Orchard
Jan 10, 2014 at 10:32 PM
Edited Jan 10, 2014 at 10:33 PM
I am able to use alternate layouts for the homepage and secondary pages content areas by using the layer options in Orchard. However, I can't figure out how to use a different layout in the header section. I tried using the layout selector module to use a different template: layout-url-homepage.cshtml, but it doesn't seem to pick up the new template when I run the site from Web Matrix. Since this is such a simple change - going from class="large-4" to class="large-3", I wonder if I can use conditional code based on the url in layout.cshtml. Any advice would be welcome.
Jan 11, 2014 at 6:32 PM
You can enable url alternates feature and try again.

You can always use code in layout template to conditionally add one css class or another. Actually this is how zone classes are added in TheThemeMachine layout template. You can check in the template file in a code block if the current request is homepage, something like that:

@using Orchard.Utility.Extensions;

string cssClass = "large-4";
if (VirtualPathUtility.ToAppRelative(Request.Path) == "~")
cssClass = "large-3";


Jan 11, 2014 at 8:44 PM
Edited Jan 11, 2014 at 9:13 PM
Thanks. I did get it working by enabling the url alternates feature. Is there a performance reason to have multiple templates vs conditional logic in one layout file? I fear a proliferation of templates which when a change is made to the site will all need to be updated.
For anyone trying this at home, the code that worked for me is
if (VirtualPathUtility.ToAppRelative(Request.Path) == "~/")
Jan 11, 2014 at 9:22 PM
I think enabling url alternates and having lots of alternates would affect performance negatively. But being a CMS and relying heavily on DB, it's not that significant for Orchard.

For your case, for just changing one css class, I wouldn't enable the url alternates and duplicate the whole layout template in a homepage alternate, and go with the code inside single layout template. But for larger differences and entirely different markup/structure having alternates is cleaner with the cost of some duplicated markup/code and some performance loss (most probably insignificant) to enabling url alternates.