I've defined a property on my home page which I'd like to show on my content pages which are children of homepage with their own templates.
The problem is I get an opportunity to set the property on each of my child pages which is not what I want.
I want to be able to set the property on the parent home page and allow the contents of the property to be inherited by the children of the home page and also for the property not to appear on the child page.
I think I'm following what you're asking but I'll explain my understanding in case I'm off!
You have a master doc type (homepage) with a lot of children. You have a property on the homepage which, because you've nested your doc types, is appearing in the children - this isn't what you want but you do want to use the "template" of the homepage site wide?
If you don't want this happening then the good news is that you can nest templates seperately from the document types. I find very little reasons to ever nest the documen types except for Meta data fields. To nest template create a "master" template (with no matching doc type - this is seperate from your homepage template though this should probably sit under this master). Your Master template will contain your outer HTML shell (headers, footers, generic div containers) and then create your templates below this.
Your templates will look something like:
Master
- homepage
- news
- anotherchild
...
But your doc types will all be at the same level (e.g. no parents).
Now you need to get the value of a property set on the homepage and have it appear on some (?) child pages? To do this get the homepage node content into a variable and use GetPropertyValue("yourProperty) ... e.g. for a "siteTitle".
@{
var homepage = Model.Content.AncestorOrSelf(1);
}
<h1>@homepage.GetPropertyValue("siteTitle")</h1>
That's the way I do it - I wonder if there is a more efficient way of accessing the properties from these nodes?
You can also set the homepage into the variable using the ID:
@* Get the homepage node via id *@
var homepage = Umbraco.Content(1001);
No problem Steve, thanks for your input. I have already got a master page and I'm using the inheritance to allow sub styling etc.
My case is a bit of a one off I think. Basically it's a multi-language website and I wanted all the text including the footer to change when the language changes. I originally put a footer property on the master so I could define different footer text on the English vs Spanish pages, the problem being that pages underneath these also inherited the property.
In the end I put my footer text in the master template with some Razer code that detects the language and blits out the appropriate header text I sequentially deleted the footer property which I think gives a cleaner layout.
Inheriting property value from parent page?
Hi,
I've defined a property on my home page which I'd like to show on my content pages which are children of homepage with their own templates.
The problem is I get an opportunity to set the property on each of my child pages which is not what I want.
I want to be able to set the property on the parent home page and allow the contents of the property to be inherited by the children of the home page and also for the property not to appear on the child page.
Is there a way to achieve this?
Many thanks,
Damien.
Hi Damien,
Yes you can achieve this by using the UmbracoHelper like this:
This enables you to use the property of parent nodes. You can also have the same property on the child if you want to override the value.
That's perfect Allan, just what I needed!
I think I'm following what you're asking but I'll explain my understanding in case I'm off!
You have a master doc type (homepage) with a lot of children. You have a property on the homepage which, because you've nested your doc types, is appearing in the children - this isn't what you want but you do want to use the "template" of the homepage site wide?
If you don't want this happening then the good news is that you can nest templates seperately from the document types. I find very little reasons to ever nest the documen types except for Meta data fields. To nest template create a "master" template (with no matching doc type - this is seperate from your homepage template though this should probably sit under this master). Your Master template will contain your outer HTML shell (headers, footers, generic div containers) and then create your templates below this.
Your templates will look something like:
Master
- homepage
- news
- anotherchild
...
But your doc types will all be at the same level (e.g. no parents).
Now you need to get the value of a property set on the homepage and have it appear on some (?) child pages? To do this get the homepage node content into a variable and use GetPropertyValue("yourProperty) ... e.g. for a "siteTitle".
That's the way I do it - I wonder if there is a more efficient way of accessing the properties from these nodes?
You can also set the homepage into the variable using the ID:
Update - I started my response before Alan posted.. I am probably way off then :)
No problem Steve, thanks for your input. I have already got a master page and I'm using the inheritance to allow sub styling etc.
My case is a bit of a one off I think. Basically it's a multi-language website and I wanted all the text including the footer to change when the language changes. I originally put a footer property on the master so I could define different footer text on the English vs Spanish pages, the problem being that pages underneath these also inherited the property.
In the end I put my footer text in the master template with some Razer code that detects the language and blits out the appropriate header text I sequentially deleted the footer property which I think gives a cleaner layout.
is working on a reply...