Copied to clipboard

Flag this post as spam?

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


  • Richard 146 posts 168 karma points
    May 10, 2011 @ 10:59
    Richard
    0

    Changing MasterPageFile in code behind

    I am working on creating a web site that is viewable with a mobile and desktop browser, and so started looking at switching the MasterPageFile, to change the MasterPage. I found this post Adding codebehind to masterpages which describes the problem. Is this still the case, that Page_PreInit() is not run, or not early enough, to change the master page in newer versions of Umbraco?

    Richard

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    May 10, 2011 @ 11:49
    Richard Soeteman
    0

    Hi Richard,

    You don't need to do this in your code behind. Umbraco has a feature called alternate templates that you can access via the url. Then Umbraco will use that masterpage instead of the default one.

    So assuming your mastertemplate alias of the masterpage you want to use for the mobile site is is called mobile, your normal url is http://yoursite.com/somepage/ all you need to do to view the mobile template is change the url to http://yoursite.com/somepage/mobile/

    Hope this helps you and pleas let me know if it din't.

    Cheers,

    Richard

     

     

  • Richard 146 posts 168 karma points
    May 10, 2011 @ 12:16
    Richard
    0

    Richard,

    I was planning on doing the following:

    Master Template => containing HTML head navigation etc

        Content Template => containing bread crumb side menus

            Item Template => containing body text, listers for news items, the central panel of the page that often changes

    And then create mobile specific Master Template and Content Templates for the site (with simplified and cut down menus etc), but keep the place holders with the same IDs. Then reuse the Item Template. This would mean that we would not new item templates for each page type, and it would keep the menu structure simpler, you would not need to have http://sitename.com/news/new_site_launched/mobileNews for a news article link, with a link back to the listing page being http://sitename.com/news/mobileNewsList.

    Hence I was hoping to switch the Content Template master page in code behind.

Please Sign in or register to post replies

Write your reply to:

Draft