+1-888-365-2779
Try Now
More in this section

Forums / Designing with Sitefinity / Nested Master Pages

Nested Master Pages

17 posts, 0 answered
  1. TexKen
    TexKen avatar
    16 posts
    Registered:
    03 Mar 2006
    15 Jul 2008
    Link to this post
    What versions of sitefinity support nested master pages w/ drag & drop functionality?  We have a 3.1 site that we're trying to add this to but it won't let us drag and drop.

    craig
  2. Joe
    Joe avatar
    138 posts
    Registered:
    24 Sep 2012
    16 Jul 2008
    Link to this post
    Hi Ken,

    Thanks for contacting us.

    Your current version can support nested master pages, however, these pages are made in Visual Studio and not in the Sitefinity Template Editor. To make a nested master page, you must set the MasterPageFile property of nested master page to the master it wants to reference. Then, add controls to the content place holders in Visual Studio. Please see the attached code sample for your reference.

    I hope that I have give you clear instructions on making a nested master page with Sitefinity. Feel free to contact us if you have any questions.

    Best Wishes,
    Joe
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. TexKen
    TexKen avatar
    16 posts
    Registered:
    03 Mar 2006
    21 Jul 2008
    Link to this post
    I'm very comfortable with master pages and creating them in visual studio.  I'm doing exactly the same thing you sent in your example.  And the master pages DO show up in sitefinity.  However, when editing a page, drag and drop functionality of the controls into the placeholders is lost.  It keeps trying to put the content into the parent master's place holders, not the inner master's.

    I can add the controls using the drop down and add button in the right bar below the list of controls, but i can't drag and drop.


  4. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    24 Jul 2008
    Link to this post
    Hi TexKen,

    Unfortunately, this is by design and could not be prevented at this time. We will try to improve this functionality in the future.

    Regards,
    Georgi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  5. Jeremy
    Jeremy avatar
    3 posts
    Registered:
    17 Apr 2008
    25 Jul 2008
    Link to this post
    Given that you loose drag and drop page/template editing from the admin console when utilizing nested masterpages.  You also loose the ability to edit the content of the control from the admin console. 

    Is it fair to say that Nested Master Pages do not work in Sitefinity?  If this is the case then please be honest when some asks about this feature and say your software does not support this feature of ASP.Net.

    I understand that it is technically possible to use nested master pages but it is definitely not practical given the limitations of the framework.

    --Jeremy
  6. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    29 Jul 2008
    Link to this post
    Hello Jeremy,

    We apologize that we didn't mention the drag and drop functionality.

    You can try using Classic Mode instead of Overlay when dragging controls. Despite the fact that you cannot drag and drop controls on the parent master page in overlay mode, is there any other thing that bothers you?

    We at Telerik highly appreciate any constructive feedback that you can provide. If you care to share your opinion on the matter, it will definitely help us to improve our CMS.

    Regards,
    Georgi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  7. Jeremy
    Jeremy avatar
    3 posts
    Registered:
    17 Apr 2008
    30 Jul 2008
    Link to this post
    Georgi,

    Thanks for the replay.  After playing with this some more I think I found a happy medium.

    --Jeremy
  8. Adam @Habanero
    Adam @Habanero avatar
    45 posts
    Registered:
    22 Jun 2012
    02 Sep 2008
    Link to this post
    Hi Jeremy

    We are currently struggling with this same issue.  Would you mind sharing what your solution was?

    Thanks
  9. Randel
    Randel avatar
    50 posts
    Registered:
    30 Aug 2012
    16 Sep 2008
    Link to this post
    What am I missing.  It seems as if nested master pages don't work.  I am not getting the parent master page to be applied to it's child master page(s).

    If I have already filled in a content place holder in "Level1.master" and "Level2.master" is one if it's children master pages, I would expect that place holder on "Level2.master" to be read-only; or at least to default to any already existing control place in the "Level1.master" page.  Instead, what I see is any content place holder, in any master page, is editable, in any template. 

    I'm also seeing that if I create a page and set it's template to "Level2", and "Level2.master" is set to have "Level1.master" as it's master page, that any theme or control applied to "Level1.master" are gone and/or ignored.  They simply do not show up when displaying the page.

    So if what I'm see is the desired results, why should I use nested master pages?  If I'm mistaken and I'm doing something wrong, please let me know and I'll fix it.

    This is what I'm trying to do.  I have created two templates: "Level1.master" and "Level2.master".  "Level2.master" has the line

     <%@ Master Language="C#" MasterPageFile="~/App_Master/Level1.master" %>

    I also have the "Edit Mode" set to "Classic", which allows for dragging and dropping of controls. 


  10. Pepi
    Pepi avatar
    981 posts
    Registered:
    28 Oct 2016
    18 Sep 2008
    Link to this post
    Hello Randel,

    You're not doing anything wrong. Let me explain you how nested master pages work in Sitefinity.

    Templates in Sitefinity are created from master pages but they are not master pages. They are stored in the Sitefinity database and keep references to the controls they contain - this means that there is no hierarchy in templates. The hierarchy in master pages is not applied to templates.

    What happens in your case is that the parent template (created from the
    parent master page) keeps a reference to the controls you've put in it. However, the child template only knows that it is supposed to show the markup of the parent, but there are no controls in that markup - only a ContentPlaceHolder, which is what you see.

    So if you want to add a control to the parent that is also seen in the template created from the child master page, you would have to add the control in the markup, and not using Sitefinity administration. In this way the control would be created in the master file itself (
    not in the database) and could be seen from the child.

    Hope the information is helpful for you.

    All the best,
    Pepi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  11. Randel
    Randel avatar
    50 posts
    Registered:
    30 Aug 2012
    18 Sep 2008
    Link to this post
    Hey Pepi,

    Thanks for the great explanation and why what is what and I wish more tech replies were like this one. 

    Your comment, "... you would have to add the control in the markup, and not using Sitefinity administration.", has me thinking.  Is it posible to insert the Sitefinity controls in my markup?  And if so, what might that look like?  Is there anything special I'd need to know or do to make sure it works as if the control was dropped onto the templete from within Sitefinitys administration?
  12. Pepi
    Pepi avatar
    981 posts
    Registered:
    28 Oct 2016
    18 Sep 2008
    Link to this post
    Hello Randel,

    Definitely, you can insert Sitefinity controls in the markup of the parent master page. Here is a simple example with the NewsView public control which displays one or more news items:

    parent.master
    <%@ Master Language="C#" %> 
    <%@ Register Assembly="Telerik.News" Namespace="Telerik.News.WebControls" TagPrefix="cc" %> 
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
     
    <html xmlns="http://www.w3.org/1999/xhtml"
    <head runat="server"
        <title>Untitled Page</title> 
        <asp:ContentPlaceHolder id="head" runat="server"
        </asp:ContentPlaceHolder> 
    </head> 
    <body> 
        <form id="form1" runat="server"
            <div> 
                <h1>Parent Master</h1> 
                <style="font:color=red">This is parent master content.</p> 
                <cc:NewsView id="NewsView1" runat="server" BehaviorMode="Master" SingleItemUrl="~/SingleNews.aspx"/>
                <asp:ContentPlaceHolder ID="MainContent" runat="server" /> 
            </div> 
        </form> 
    </body> 
    </html> 

    Hope this helps.

    All the best,
    Pepi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  13. Randel
    Randel avatar
    50 posts
    Registered:
    30 Aug 2012
    18 Sep 2008
    Link to this post
    Hey Pepi,

    Your reply is exactly what I needed; and again, I wish all the tech replies were this helpful.

    Now, am I correct with making the assumption that, just like controls, an applied theme is held in the database too?  And, if I want me nested master page to have the same theme, that I'll have to assign that manually too?  If so, what's the best way to do that?
  14. Randel
    Randel avatar
    50 posts
    Registered:
    30 Aug 2012
    18 Sep 2008
    Link to this post
    Also, is there a list to help me know what assembly belongs to what control?  In the example you gave me, you used the "Telerik.News" assembly from the "Telerik.New.WebControls" namespace.  If I don't know the "NewsView" is in this area, where would I find that information?  Does this make sense?

    Thanks again for a the great help.
  15. Pepi
    Pepi avatar
    981 posts
    Registered:
    28 Oct 2016
    19 Sep 2008
    Link to this post
    Hello Randel,

    MasterPage has no Theme property. That is the reason why you cannot directly (manually) apply an ASP.NET theme to a master page. If you add a theme attribute to the @ Master directive, the page will raise an error when it runs.

    A possible solution is to set themes only for the child templates using Sitefinity interface. Master pages are resolved in the context of content pages, so the content page's theme is applied to the master page as well.

    Another approach is to apply themes programmatically. To achieve this in Sitefinity, do the following steps:
        1. Create a new class in App_Code folder that inherits from Telerik.Cms.Web.InternalPage and override OnPreInit method. Your custom logic should be implemented in this method. For example:

    .cs
    using System; 
    using System.Data; 
    using System.Configuration; 
    using System.Web; 
    using System.Web.Security; 
    using System.Web.UI; 
    using System.Web.UI.HtmlControls; 
    using System.Web.UI.WebControls; 
    using System.Web.UI.WebControls.WebParts; 
     
    public class CustomPage : Telerik.Cms.Web.InternalPage 
        protected override void OnPreInit(EventArgs e) 
        { 
            base.OnPreInit(e); 
            if (this.Master.MasterPageFile ==  "Parent.master"
                this.Page.Theme = "Orange with left sidebar"
        } 

        2. Replace the declaration of InternalPage class with the name of your newly created class in the following file ~/Sitefinity/cmsentrypoint.aspx like this:

    .aspx
    <%@ Page Language="C#" Inherits="CustomPage" MasterPageFile="~/Sitefinity/Dummy.master" %> 

    Regarding your second question about the assemblies, I would recommend you investigate Sitefinity API that is described in the Developer Manual.

    Do let us know if you need any further assistance.

    Best wishes,
    Pepi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  16. Mark Bice
    Mark Bice avatar
    1 posts
    Registered:
    23 Jun 2006
    21 Oct 2008
    Link to this post

    We had similar problems with nested master pages and have settled for using contentplaceholders in the parent and creating new contentplaceholders in each child master (which can have controls dragged/dropped into them).

    couple of questions i have:

    1.  Our parent master contentplaceholders are essentially useless at this point so we re-create placeholders in each child master so that controls can be dragged/dropped.  So we don't need the parent's contentplaceholders to show up in edit mode.  Is there a way to hide them altogether so that the user can only drop controls into the CHILD master's contentplaceholders?
    2.  Has anyone tried using regular asp placeholders in the parent master and then programatically add content to them in each child master?

    thanks!

  17. Pepi
    Pepi avatar
    981 posts
    Registered:
    28 Oct 2016
    27 Oct 2008
    Link to this post
    Hi Mark,

    1. Sitefinity does not provide an option to hide the parent ContentPlaceHolders. As a workaround I would suggest you use Overlay edit mode instead of Classic. In this mode the user cannot drag and drop controls into the placeholders of the parent.
    2. Here is a simple example how to programmatically add a new LiteralControl to the template:

            // create a new instance of CmsManager 
            Telerik.Cms.CmsManager cmsManager = new Telerik.Cms.CmsManager(); 
            // find the template with name "Child" 
            Telerik.Cms.IPageTemplate template = cmsManager.GetTemplate("Child"); 
            Guid templateId = template.ID; 
            // get template object associated with a transaction in order to modify it 
            Telerik.Cms.IPageTemplate templateForEditing = cmsManager.GetTemplate(templateId, true); 
            // check out the template for edit 
            Telerik.Cms.IStagedPage staged = templateForEditing.Staged.CheckOut(); 
            // add the control to "MainContent" placeholder 
            staged.AddControl("MainContent"new LiteralControl("Add control programatically!")); 
            templateForEditing = cmsManager.GetTemplate(templateId, true); 
            // check in the template 
            templateForEditing.GetVersion(staged.Version).CheckIn(); 

    Also, you could investigate the following topic of the Developer Manual: Modifying Template

    Hope you will find the provided information helpful.

    Kind regards,
    Pepi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Register for webinar
17 posts, 0 answered