Copied to clipboard

Flag this post as spam?

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


  • Brian A 13 posts 34 karma points
    Aug 04, 2010 @ 19:38
    Brian A
    0

    Change Masterpage <div> from childpage?

    Hi All,

    I'm new to Umbraco so please bare with me.

    I have a site where I use masterpages and childs. On the masterpage I have a <div> containing a background image in which I would like to change when moving to the childpages.

    How can this be done?

    Snippet from master.template: 

    <div id="mainContent">
        <div id="contentContainer">
          <asp:ContentPlaceHolder ID="bycaloContentPlaceHolder" runat="server"></asp:ContentPlaceHolder>
          <div id="clear"></div>
        </div>
      </div>

    CSS:

    #mainContent { background-image: url(/media/mainCont_back.png); background-repeat: repeat-x; }

    Thanks in advanced!

    Rgds

    Brian

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Aug 04, 2010 @ 20:24
    Matt Brailsford
    0

    Hi Brian,

    I tend to create a number of classes on the body tag as follows:

    <body class='t<umbraco:Item runat="server" field="template"/> dt<umbraco:Item runat="server" field="nodeType"/> p<umbraco:Item runat="server" field="pageID"/>'>

    Basically this creates 3 classes

    1) txxxx - 't' + the template id
    2) dtxxxx - 'dt' + the doc type id
    3) pxxxx - 'p' + the page id

    Then you could just create a class per template/doctype/page

    .p1234 #mainContent { background-image: url(/media/mainCont_back1.png); background-repeat: repeat-x; }
    .p1235 #mainContent { background-image: url(/media/mainCont_back2.png); background-repeat: repeat-x; }

    This method assumes the images are hard coded. Let me know if that's not the case.

    Matt

  • Bogdan 250 posts 427 karma points
    Aug 04, 2010 @ 20:33
    Bogdan
    0

    I think you can access controls from the master page using the Master property of a page: Master.FindControl("someId"). So you can add runat="server" to the div and try to find it from the child page. You can have a .net macro in the child page that does this.

    Hope this helps!

  • Jeff Grine 149 posts 189 karma points
    Aug 04, 2010 @ 20:46
    Jeff Grine
    0

    I use a variation of what bfi suggested. You can put a public property on your master that you use for the class. Then in the child create an instance of the master and you can set the value of the public property. Something like this:

    MyMasterPage mmp = Page.Master.Master as MyMasterPage;
    mmp.PublicProperty = "whateverClassForTheChild";
  • Eric Boen 40 posts 64 karma points
    Aug 04, 2010 @ 21:38
    Eric Boen
    0

    We often add a ContentPlaceHolder in the parent template located in the <head> tags.  Then in the child templates we'll add javascript specific for the internal pages.  In the example below the Parent template would include a reference to jQuery and have a ContentPlaceHolder below the reference also in the <head> tag. Then in the child templates we add the content area that is associated with the ContentPlaceholder on the parent template.  Now we just add the jQuery below to swap out a background image.

      <script type="text/javascript">
        $(document).ready(function ({

    $('#mainContent').css("background-image""url(/media/internalpagebackground.jpg)");

        });
      </script

    Good luck

    Eric

  • Brian A 13 posts 34 karma points
    Aug 04, 2010 @ 23:41
    Brian A
    0

    Woaoh - thanks for all the great answers!

    /Brian

Please Sign in or register to post replies

Write your reply to:

Draft