Copied to clipboard

Flag this post as spam?

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


  • Dieter Walckiers 9 posts 29 karma points
    Dec 15, 2011 @ 18:28
    Dieter Walckiers
    0

    Master template properties not being used in child template

    Hello community!

    I have a beginners question on which I couldn't find the answer.

    I have a master template like so:

    <%@ Master Language="C#" MasterPageFile="~/masterpages/Authentic.master" AutoEventWireup="true" %>
    <asp:Content ContentPlaceHolderId="BodyContent" runat="server">
       <!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>
        <title>Your Page Title Here</title>
      </head>
      <body style="background-color:<umbraco:Item field='bgcolor' runat='server'/>">
      <umbraco:Item field="achtergrondkleur" runat="server" />
      master body
    <asp:ContentPlaceHolder Id="RootContent" runat="server">
      <!-- Insert default "RootContent" markup here -->
    </asp:ContentPlaceHolder>
      </body>
      </html>
    </asp:Content>

     

    and a child template:

    <%@ Master Language="C#" MasterPageFile="~/masterpages/Root.master" AutoEventWireup="true" %>
    <asp:Content ContentPlaceHolderId="RootContent" runat="server">
    child body
    </asp:Content>

    They both have document types with the same names, and "bgcolor" is a valid property of the corresponding document type for the master template.

    Then, I add content; a page based on the master, and a subpage based on the child template, and set the bgcolor property of the master page to "#FF0000" for example. When I launch the master page, the background color is nicely red. But when I view the child page, it stays blank.

    I was expecting that the background color for the child page would also be red, as the master and child page are being merged?

    I'd like to set up some basic properties for my website in my master template so I don't have to repeat them in every page.

    I hope my question is clear.

    Thanks in advance

    Dieter

     

     

     

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Dec 15, 2011 @ 18:33
    Tom Fulton
    0

    Hi Dieter,

    The problem is the bgcolor field will read from the child page when you view it.  The <umbraco:Item> fields always pull its info from the currentPage, it doesn't matter where they are in the template (master/child).

    However, you can specify recursive="true" on your <umbraco:Item> tag.  This will cause it to retrieve the property from itself or it's closest parent that has the property filled out.  So if the property is blank in your Child page, it will attempt to check the Parent page and use that value, etc.

    <body style="background-color:<umbraco:Item field='bgcolor' runat='server' recursive='true'/>">

    Hope this helps,
    Tom

  • Dieter Walckiers 9 posts 29 karma points
    Dec 16, 2011 @ 11:14
    Dieter Walckiers
    0

    Yes!!

    Now I remember I saw that in one of the videos... 

    Thanks a lot for helping out!

Please Sign in or register to post replies

Write your reply to:

Draft