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.
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.
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
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.
Hope this helps,
Tom
Yes!!
Now I remember I saw that in one of the videos...
Thanks a lot for helping out!
is working on a reply...