How are views linked to the razor templates

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 years ago
Hi

I have a working installation of NOP 2.2. I want to create a custom layout for the homepage, which i thought i could do by creating two new Layout files to link the view too, so i created

_ColumnsOneHome (a copy of _ColumnsOne)

_RootHome (a copy of _Root)


I changed the Index view in the home views folder to inherit the new layout

Layout = "~/Views/Shared/_ColumnsOneHome.cshtml";

I also changed ColumnsOneHome.cshtml to inherit the new root layout

Layout = "~/Views/Shared/_RootHome.cshtml";

but when i view this in the browser i can see the old layout files are still being used, i can tell because i have changed the class names in the new _RootHome layout and added some new css, but i can still see the old class names in the HTML when i debug with firebug,

is there anything that could be overriding the layout declaration inside the view?

many thanks in advance for any advice anyone can offer

regards

Liam
12 years ago
After further testing with this I am even more confused

as it appears that the home view is actually linked to _ColumnsFluid not _ColumnsOne as the declaration inside the view states.

I think this because i linked _ColumnsFluid to my custom _RootHome

    Layout = "~/Views/Shared/_RootHome.cshtml";

i can now see _RootHome is being used for the index view of the home folder as my new class names are visible when viewing the page in firebug.

What i need is for the homepage to be using its own layouts, but i can see the same behaviour with the ContactUs page, the declaraion in the view states

    //Layout = "~/Views/Shared/_ColumnsTwo.cshtml";

But my class names are also visible on that page so it must also be linked in some way to ColumnsFluid.

The homepae will be very different to the rest of the pages in terms of background colour etc.... so i need it to use its own layouts so the rest of the site is not affected by the changes i make.

I must be missing something, any ideas?
12 years ago
If anyone is interested the only way i could get this to work was to override the homepage Index views layout in the controller action with,

return View("Index", "_ColumnsOneHome");

simply changing the layout declaration inside the view doesnt work,

i would still be interested to know how when i changed _ColumnsFluid to inherit my custom _RootHome, the following pages all inherited the _RootHome despite their layout declarations contained inside the views.

blog - _ColumnsTwo
contact us - _ColumnsTwo
recently viewed products - _Columns Three
compare products - _ColumnsTwo
sitemap - _ColumnsOne
search results- _Columns Three
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.