Attributes that get inherited by child pages

Permalink 1 user found helpful
The idea is fairly simple. I'm want to add an attribute to a page, and have that attribute get inherited by all associated child pages.

The end result is auto page categorization based off the site structure.

I could just add an attribute to every page manually, but that seems unnecessary if I can just set it once and automate it afterwords.

Here's an example to help visualize what I'm looking for:

- Home
- About
- Animals (selected attribute: "animals")
--- Cats (inherited attribute: "animals" / selected attribute: "cats")
------ Persian (inherited attribute: "animals" / inherited attribute: "cats")
------ Tabby (inherited attribute: "animals" / inherited attribute: "cats")
------ Maine Coon (inherited attribute: "animals" / inherited attribute: "cats")
--- Dogs (inherited attribute: "animals" / selected attribute: "dogs")
------ American Eskimo (inherited attribute: "animals" / inherited attribute: "dogs")
------ German Shepard (inherited attribute: "animals" / inherited attribute: "dogs")
------ Pug (inherited attribute: "animals" / inherited attribute: "dogs")
--- Horses (inherited attribute: "animals" / selected attribute: "horses")
- Contact

-----------

I looked around and I thought this,http://www.concrete5.org/index.php?cID=329481&editmode=... , might be referring to what I'm looking for. But it was difficult to tell. I'm still not entirely sure but I didn't give that a try as it sounded a little too complex for my needs.

Thanks for the help!

roketto
 
A3020 replied on at Permalink Reply
A3020
What you *can* do, is hook into the on_page_add event. When a page is created, you can loop the parent pages and assign their attributes to the newly created page.

More info:http://www.concrete5.org/documentation/developers/system/events/...
roketto replied on at Permalink Reply
roketto
Not a bad idea. I can see this being an issue if I decided to remove/change the parent page attribute, since the children wouldn't update along with the parent.

That being said, I would rather implement this than nothing.

Could you provide an example for how I would actually code this functionality using the on_page_add event?

Thanks!
A3020 replied on at Permalink Reply
A3020
First you need to hook into the event. Once you've got that working, you receive the page object in your function as a parameter.

Use the 'getTrailToCollection' function to get all parent pages:http://www.concrete5.org/documentation/developers/helpers/navigatio...

I don't know how you set up your attributes, but you can simply use $page->setAtribute('name', 'value') to assign a value to a page and use $page->getAttribute('name') to retrieve one.