Creating a MasterPage

Nov 21, 2008 at 4:46 PM
Hi everyone, im new in N2, i think its a great CMS, but i have lack of information regarding the documentation. I have a simple project and i want to create my own MasterPage, i dont find where in the project i can specify to pages whats the masterpage to use, it seems to use always the top+submeny.master. Any thoughts?

Thanx
Coordinator
Nov 21, 2008 at 5:12 PM
You can change master page using configuration:

<n2><templates masterPageFile="~/yes.master" />
Nov 21, 2008 at 5:43 PM
libardo, thanx for the quick response. But what if i need to define more than one masterpage in my site? Can i do that?
Coordinator
Nov 21, 2008 at 9:18 PM
The masterpage is applied to aspx:es inheriting from N2.Templates.Web.UI.TemplatePage. There are some ways to overcome this (inheriting from something else, overrideing OnPreInit, defining a custom IPageModifierContainer service). What do you want to accomplish? When would the masterpage differ?
Nov 24, 2008 at 1:59 AM
I want to have in my site some pages with a masterpage, and the others with another one, similiar but not the same. Doing something of what you've told before works for that?

Thanx
Jan 5, 2009 at 1:34 PM
Edited Jan 5, 2009 at 1:37 PM
I have the same problems, because CSS styles can't solve all problems, sometimes it's need to make some different html templates.
It will be great if we can change MasterPage templates on Themes Level or later on usual pages.
Jan 5, 2009 at 7:56 PM
If all that you want is to apply theme to all pages at once AND you don't want to inherit from TemplatePage<T>, then don't forget about an old trick of configuring .aspx pages via web.config:

<system.web>
...
<pages theme="MyTheme" styleSheetTheme="MyTheme" />
...
</system.web>

Jan 5, 2009 at 9:12 PM
I want that different html layouts could be applied to dofferent ContentItems!
Jan 5, 2009 at 10:00 PM
Aha, so you'd like to have the same functionality, but a different presentation variants that vary so much, that they cannot be implemented with CSS, right ? Say, you want to re-order certain things, which would lead to a enormous hackery if done with CSS. Yes, ASP.Net's answer to this problem is .masterpages. And, yes, sad but true, is that .masterpages are not integrated with ASP.Net's themes. 

N2's custom solution to the problem of dynamically associating different .masterpages for presentation, as Cristian has pointed out, is to derive your page from the TemplatePage<T>, this way, a base class decides which .master to apply, but again, it is unrelated to a theme. If you want even more advanced solution for having .masterpages bound to themes -- see how Mads has implemented skinning in BlogEngine.NET (right in the beginning of BlogBasePage.cs file) (yes, an unintentional advertisment for another great project ;-) Btw, just realised that implementing BE's approach would be very easy in N2: 1) Add another configuration property 2) Copypaste .master application logic from BE into TemplatePage<T> 3) Establish another strict convention in N2, something like: "thou shalt put your .master into dedicated folder with all associated UI stuff and forget about App_Themes .." and set the path to this folder in the property [1], repeat [3] as needed..
Jan 5, 2009 at 11:21 PM
Anyway, such functionality should be implemented with adding some new fields (like theme field when editing StartPage root, but this field should contain currently using MasterPage filename) in admin backend, when editing ContentItems. I think this feature is very useful and will extend project capabilities.
Coordinator
Jan 6, 2009 at 11:32 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
May 14, 2009 at 9:08 PM

Why is it not possible to create your own versions of TextPage.cs, Text.aspx/Text.aspx.cs ? Which specify their own masterpage? I tried this, however it seems either I have missed somethnig or N2 forces me to use the top+sub default master page.. I have included a link to the RAR of my addon, if someone wants to look at it? I want there to be an option when you right click and create a new page for my different layouts.

http://www.gotmojito.co.uk/n2/addons/Layout.rar

 

 

May 15, 2009 at 12:02 PM

On another note, what happens if you change the layout of a page at runtime to a layout which doesnt have the same zones etc?..

Cristian, earlier in this post you also say that you can force your masterpage to be used by N2.. how can this be done using the methods you mention? Obviously using MasterPageFile="" in the <%@ Page directive doesn't work, and seems to be overridden by N2. I would like to have a clean way to tell it just to use the MasterPage shown in the MasterPageFile="".

Cheers
Pete

Coordinator
May 15, 2009 at 5:12 PM

If you inherit from TemplatePage<> you get the behaviour you're describing. You can inherit from ContentPage<> instead if you want more freedom.

May 15, 2009 at 9:38 PM

As an alternative to inheriting from N2.Templates.Items.* (wich is quite restrictive), one can just apply a special extension method to an arbitrary page during OnInit event to get all the goodies of Templates behavior (dynamic master page, themes, syndication, whatever)