Hi,
is there any way to achieve a content inheritance? Let’s say any of my pages could have a field twitter
. If for a page this field is empty or does not exists, I would like to use the parent’s field twitter
which is closest and not empty; or, if no parent has a twitter
field set, fall back to a default.
Take this content structure, where the twitter
field may or may not exist. If it does not exists it should inherit its value from the closest existing parent’s value.
home (no `twitter` field exists. Fallback to -> example)
Project 1 (`twitter` field exists, but is empty. Fallback to -> example)
| Subpage 1 (`twitter` field does not exists. Inherits from parent -> example)
| Subpage 2 (`twitter` is set to -> sub12)
Project 2 (`twitter` is set -> project2)
| Subpage 3 (`twitter` field does not exists. Inherits from parent -> project2)
| Details 3.1 (`twitter` exists but is empty. Inherits from closest parent where it is set-> project2)
| Details 3.2 (`twitter` is set -> details32)
| Subpage 4 (`twitter` is set -> sub4)
| Details 4.1 (`twitter` exists but is empty. Inherits from parent -> sub4)
| Details 4.2 (`twitter` does not exist. Inherits from parent -> sub4)
| Details 4.3 (`twitter` is set -> details43)
I know of the $page->parents()
function, with which I could iterate over all parent pages, but maybe there’s an easier out-of-the-box method for this which I have missed. I’d be grateful for any suggestions
Cheers,
Frederik