Custom masterpage for home page.

Topics: Business Logic Layer, Themes
Jun 14, 2009 at 12:54 PM

Hi guys been playing about with BE for a while and really like it.

I just developed a new feature that enables a custom masterpage for the "frontpage".

This is something i needed for one of my sites - the home page needed to be full of stuff that other pages didnt need to show, so i needed the ability to use a different masterpage.

If anyone is interested in the code, let me know...

 

Cheers

Joe

 

Jun 14, 2009 at 1:07 PM
i am interested in this feature - can you share your code with me via an email - my email address is davidmiles@spamarrest.com
Jun 14, 2009 at 4:43 PM
Edited Jun 14, 2009 at 4:43 PM

Email Sent..

For the rest of the world, here was my solution.. Its not had a huge amount of testing, so if you find any issues please let me know!

 

Change is quite simple, just impacts two files.
namespace BlogEngine.Core.Web.Controls
----- BlogBasePage.cs----
1. Declare a new class level variable:
protected string _MasterPageName = null;
2. Change the OnPreInit event to look like this...

            if (Request.QueryString["theme"] != null)
_Theme = Request.QueryString["theme"];

            if (_MasterPageName == null)
            {
                _MasterPageName = "/site.master";                
            }
            
            MasterPageFile = Utils.RelativeWebRoot + "themes/" + _Theme + _MasterPageName;
          
  
    base.OnPreInit(e);


BlogEngine.Web
------ Page.aspx.cs ---------
1. Add override for OnPreInit
protected override void OnPreInit(EventArgs e)
    {  
        if (Request.QueryString["id"] != null)
        {
            Guid id = new Guid(Request.QueryString["id"]);
            BlogEngine.Core.Page p =  BlogEngine.Core.Page.GetPage(id);

            if (p !=null && p.IsFrontPage)
            {
                _MasterPageName = "/home.master";
            }
        }

        base.OnPreInit(e);
    }
Pretty simple really :)

 

Jul 10, 2009 at 10:55 PM

Hello, I have tried as explained above, but it is not working. I am not getting any errors, it just continues to load site.master. any ideas what I could be missing

Jul 10, 2009 at 11:02 PM

put some break points in the code you've changed and step through it.

The key part of is is:

 if (p !=null && p.IsFrontPage)

  {

_MasterPageName = "/home.master";

}


Jul 10, 2009 at 11:42 PM

My Mistake, I assumed it meant the default.aspx. But it is the page you designate as the front page. Thanks

Jul 30, 2009 at 3:08 PM

Hi there - I am currently reviewing several blog pacakges to add to a website and don't want the blog section to be any different thematically than the rest of the site (the user shouldn't be aware that they are in a 3rd party coded portion of the site)...  Can you give a URL where you've added BE to an existing site?  Is it possible to just display certain core aspects (i.e. Posts, Categories) of BE on an existing aspx page/master page (this is what I'm really aiming for)?  Thanks!

Jul 30, 2009 at 5:33 PM
Edited Jul 30, 2009 at 5:34 PM
changemystrings wrote:

Hi there - I am currently reviewing several blog pacakges to add to a website and don't want the blog section to be any different thematically than the rest of the site (the user shouldn't be aware that they are in a 3rd party coded portion of the site)...  Can you give a URL where you've added BE to an existing site?  Is it possible to just display certain core aspects (i.e. Posts, Categories) of BE on an existing aspx page/master page (this is what I'm really aiming for)?  Thanks!

 I built a whole site for someone using BE.net, and you would never know..

Colour scheme and layout was chosen by the client, but site can be found here www(dot)kikodo(dot)co(dot)uk

Makes extensive use of Pages, with only a few Blog type sections for news, courses etc.

BE.NET can easily be used as a content management system for an entire site...