pagetree inherit

Permalink 1 user found helpful
as it seems page attributes can not be inherited to child pages i am a little bit curious as you folks would solve a simple task.
(i am completly new to c5 but as always seem to directly run into limitations :)

mission:
a website with different section - to keep it simple say:

website.com
- website.com/male
- website.com/female

every branch has a gazillion of subpages so you don't want to edit every subpage.

background-color should be blue for boys and pink for girls (as one should expect :)

sounds trivial to me coming from typo3 - but not so in c5 i guess ...

any hints how to do this?

 
leinteractive replied on at Permalink Best Answer Reply
leinteractive
There are a few ways to do this.

1.) Create a separate Page Type, one each for Male and Female. Set your background color based on the page type, this will apply to every page of that type.

2.) You can use a Page Attribute to select a color and then from within your template, you can programatically apply that color as the background, and if the attribute is not set, you can make it grab the attribute from the parent page, if not set there, go up again all the way through the sitemap until it finds a page with the attribute set to get the color from. Like this:

$nh = Loader::helper('navigation'); //need this to get the path to the page
$cobj = $nh->getTrailToCollection($c); //get the path to the current page
$bgColor = $current->getAttribute('background_color'); //gets the background_color attribute from the current page.
if(isset($bgColor)) {
   $bgColor = $bgColor; //checks to see if the bgColor is set on the current page. If it is, we're done.
} else {
//if not, go through each page in the path to the page and check for the bgColor, if you find it and stop, if not, move on to the next one.
  foreach($cobj as $level):
    if(is_object($level)) {
      $bgColor= $level->getAttribute('background_color');
      if(isset($bgColor)) {
         $bgColor = bgColor;
         break;
      }   
    }


Once you have the color, you can apply it wherever you need.
flinguin replied on at Permalink Reply
does exactly was i was looking for - thanks for the quick respone.
leinteractive replied on at Permalink Reply
leinteractive
One quick note, the code I gave you a slightly outdated...it still might work...but the better way is to not use the "isset" function.

So change everywhere it's used from this:

if(isset($bgColor))


To this:
if($bgColor)