alex
alex

Reputation: 1350

Umbraco: Property inheritance

My content structure is like this:

-Home
  -Page1
     -SubPage1
        -SubSubPage1
        -SubSubPage2
     -SubPage2
  -Page2
  -Page3

Q: How can I set a property only once in Page1 so that is inherited by all pages under it and visible only in those pages and not the parent (Page1). Currently I have a master template (Layout) that renders the main content containing a single template for most of pages that checks for HasProperty && HasValue

Upvotes: 0

Views: 489

Answers (1)

Digbyswift
Digbyswift

Reputation: 10400

If the sub-pages don't actually need the value to be set on them, but do need the value to be displayed on them when published (because the are descendants of the Page1), then you can do this in your template:

@if(Model.Content.Ancestors("Page1DocTypeAlias").Any()){
    @Model.Content.Ancestor("Page1DocTypeAlias").GetPropertyValue("propertyAlias")
}

This will check whether the current page is a descendant of Page1 (or specifically a page of type "Page1DocTypeAlias"). If it is then it will extract the property from Page1 and display it.

Upvotes: 2

Related Questions