Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • theevilgeek 15 posts 90 karma points
    Aug 21, 2009 @ 22:49
    theevilgeek
    0

    dynamic master page

    I'm working on a web application that leverages the Umbraco API to display pages for my users. When a user signs up to use my site, he or she will pick one of two layouts (that are significantly more different than stylesheets alone would support). Each of these layouts is implemented as a master page with identical content holders (so that both can be extended in the same way).

    Further, there is a third template (subpage) that extends one layout master page or the other -- this template provides much of the content and includes all property expansions for a common document type. The master pages strictly provide layout/design for this more general content template.

    Without duplicating the general content template (once for each master), I would like to embed some logic along the lines of (psuedo-code):

    if(currentUser.UsePrimaryLayout)
    {
    Page.MasterTemplate = TemplateForPrimaryLayout;
    }
    else
    {
    Page.MasterTemplate = TemplateForSecondaryLayout;
    }

    I feel that if I can access the "code-behind" for the associated umbraco node (content page), I might be able to dynamically alter which master template the general template inherits from.

    In short, I am searching for a way to toggle between layout for a common template without duplicating code and without relying solely on CSS.

     

    Thank you tremendously!

  • Paul Blair 466 posts 731 karma points
    Aug 21, 2009 @ 23:46
    Paul Blair
    0

    Sounds like what you need is .NET themes or skins. It has been discussed on this thread:

    http://our.umbraco.org/forum/developers/extending-umbraco/2130-how-to-use-aspnet-themes-and-skins-with-umbraco

  • theevilgeek 15 posts 90 karma points
    Aug 22, 2009 @ 00:16
    theevilgeek
    0

    Hi Paul,

    I'm not sure this will afford the flexibility that we'd need -- we want to be able to completely re-arrange the page (i.e., define a brand new set of markup with the same contentplaceholders). As I understand it, themeing and skins within ASP.NET allows for customized control presentation much in the same way CSS allows for presentation of HTML to be customized. That said, a complete layout is the marriage of both CSS and HTML and so (unless I don't understand the link provided) we need some more akin to the ability to swap in a totally different master template on the fly. Is there a way to achieve something like this with Umbraco? We're getting pretty desperate :(

    Thanks for your help!

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Aug 22, 2009 @ 00:20
    Aaron Powell
    1

    In Umbraco 4 all templates are ASP.NET Master Pages, so you can add your own code behind, all you have to do is set an inherits attribute of the master page. See http://msdn.microsoft.com/en-us/library/ms228176.aspx

    Then you can put your custom code in the pre init event (I think that's the best one).

  • Rick Mather 42 posts 124 karma points
    Aug 23, 2009 @ 20:28
    Rick Mather
    101

    Don't know if you've managed to find a workaround yet, but I can see this being a bit more awkward than it should be as ASP.NET Master Pages don't have an OnPreInit() event which is the only place where you can dynamically change themes and master pages. I think the cleanest way to do this would probably be to create a HTTP Module.

    I found the following article invaluable when I was learning about what you can and can't do with Master Pages, which also conveniently contains an example showing how to implement IHttpModule to dynamically switch master pages:

    http://www.odetocode.com/articles/450.aspx

  • theevilgeek 15 posts 90 karma points
    Aug 24, 2009 @ 15:47
    theevilgeek
    0

    An emphatic "thank you" to both Slace and Rick. These solutions are exactly what I was looking for. In particular, adding a simple HTTP module to Umbraco is just about ideal (if only I can figure out a convenient way to distinguish between Umbraco management Pages and actual site Pages -- but I think this shouldn't be too hard).

    I wish I could flag both answers as being the solution as they both get the job done, though in slightly different ways.

    Again, thank you both *so much* for your help. I am constantly impressed by the extremely generous and knowledgable community surrourding Umbraco.

  • theevilgeek 15 posts 90 karma points
    Aug 24, 2009 @ 22:33
    theevilgeek
    0

    It seems that I spoke too soon :) Due to the way in which Umbraco dispatches requests (all URLs seem to map to default.aspx), it is not quite clear how to use the last approach given that the page is generated dynamically (there is no ASP.NET Page object). Further, I'm not sure whether the former approach can work as it seems that all templates are masters by default, though I haven't yet tested turning the master into a regular page as of yet.

    Discussion is ongoing at: http://our.umbraco.org/forum/developers/api-questions/3732-IHttpModule-and-Umbraco

Please Sign in or register to post replies

Write your reply to:

Draft