This project is read-only.

Template Layout or Master

Topics: Developer Forum
Jan 8, 2009 at 3:34 PM
I understand that N2 CMS is made up of
  • N2 library: functionality to store and load data to the database, map url:s to content and other useful components
  • Edit: Uses N2 library to visually manage the content of a site
  • Templates: A set of funtionality like news and content pages with styles and layout

that is I do now, I think.

Before I took the C# example and was wondering why I couldn't find the menu to change which master page, or theme via the start page edit Advanced tab. I now know this is part of Template, and can see this is populated from the Layouts folder, and Asp.Net theme folders.

Confusingly the documentation talks about master pages under templates

If I want to create a new master page, should I do this as a new layout? Would modifying these template files make it harder to upgrade later?

What I would like to achieve is to have a top level master page
that just contains a standard master page with no special n2 syntax. Content placeholder for anywhere any special n2syntax is to go.

A n2 top level master page
which uses BaseMaster.master as its master page and inherit from N2.Web.UI.MasterPage, and will contains any special n2 syntax

Then all existing pages outside of the CMS can use BaseMaster.master
And all of the pages inside the CMS can use LayoutMaster.master.

Additionaly via the admin page for the startpage I would like to allow the user to select the master page, and more importantly change the theme.
Is the above possible?

Also when I was using the Template sample I created several startpages, but the first startpage theme applies to all the other start pages and subpages, leaving the other start page theme settings ignored. Is n2 template meant to be able to support multiple startpages running seperate themes? Not sure if I need these, but thought would point out.
Maybe this is coved by
Jan 8, 2009 at 4:10 PM

don't know if this is good or not, but as proof of concept have modified one of the Layouts to inherit from a seperate master page (of type MasterPage, as oposed to N2.Web.UI.MasterPage<N2.ContentItem>).

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
    <asp:ContentPlaceHolder ID="head" runat="server">
<body runat="server">
    <form id="form1" runat="server">
            <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
            Time master

layout master
<asp:Content ContentPlaceHolderID="head" runat="server">
<title runat="server" title='<%$ CurrentPage: Title %>' />
<asp:Content ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
        <n2:SlidingCurtain runat="server">
            <n2:DragDropControlPanel runat="server" QuickEditLink-Visible="false" />

anyone got a better solution.

A guide on how to extend the Template system would be handy.
Jan 8, 2009 at 4:17 PM
Just to clarify

The layout master page still inherits from N2.Templates.UI.Layouts.DefaultLayout
and the top level master page inherits from MasterPage.
Jan 8, 2009 at 8:14 PM
To exchange the default master page in the templates project you can use configuration:

<n2><templates masterPageFile="~/My.Master" />

To change master page without changing the configuration you would need to resort to some form of hackery. It's not impossible but it's exactly easy either.

I can look into an extension point to enable this scenario for future versions.
Jan 9, 2009 at 9:46 AM
Thanks for the information.

The extension sounds good.

I'm guessing the code for the advanced tab that allows you to select a skin and a layout is hidden away in the template code, and modifying this would make it difficult to upgrade later?
Would it be possible to allow for the code that populates the layout list to be extended to allow for extra master pages to be added, and/or for a CustomLayouts folder to be added by default where developers/designers can place custom masterpages which will automatically be added to the layout drop down list.

Alternatively if not using template how difficult would it be to reimplement the advanced tab which allows for changing the master page and skin, this has to happen in Page_Preinit, and I'm not sure with n2 without as you say hackery you can do this. Where does it persist this information to at the moment, and I presume somewhere in the "TemplatePage" class in Page_Preinit it selects the correct master page/layout have fetched this information from the persistence layer.

Another idea for master page changing is at the moment you can change it to any of the ones in the folder, it might be an idea to allow each template to specify an interface that the master page must implement to ensure that the necessary contentplaceholders are on the masterpage. Then when displaying the list of masterpages/layouts to filter the masterpages to the ones that implement the interface.
At the moment with template all the pages seem to have to use the same layout/masterpage so this interface idea to filter pages doesn't have much use, which leads to my second suggestion of allowing multiple masterpages/layouts per site.
An alternative to using interfaces is to just have sub folders off Layout and CustomLayouts which group the compatible master pages together, although then each masterpage can then only be in one group, where as with interfaces a single master page could implement several interfaces.
If allowing multiple master pages per site then I guess you would specify in the startpage the default master page, and then on each page allow for the masterpage to be overridden again via the advanced tab, or if the page has a different masterpage interface than the start page that is incompatible with the start page masterpage then another masterpage would have to be selected anyway.

Maybe I'd need to come up with my own version of Template, or would this fit in with Template?
Is there a guide of how to extend Template?