Is there a way to get to getCollectionAttributeValue of a parentID for all pages deeper then the parent pages of home?

Permalink
I know there is something like:
<?php
$page = Page::getByID($c->getCollectionParentID());
print $page->getCollectionName();
?>
But is there a way to get something like getCollectionParentAttributeValue() ?
And then only if the page is a child of a child from home?

vincedelaking
 
glockops replied on at Permalink Reply
glockops
<?php
$parent = Page::getByID($c->getCollectionParentID());
// Remove the last part of this while statement if you ONLY want to avoid
// getting the attributes of the homepage.
while($parent->getCollectionID() > 1 && $parent->getCollectionParentID() > 1) {
   echo $parent->getCollectionName();   // Echo your attributes here. $parent is a full page object.
   $parent = Page::getByID($parent->getCollectionParentID());
}?>
vincedelaking replied on at Permalink Reply
vincedelaking
Hi Daniel,

Feel like a real novice, I have placed your code in my header.php, but how do I parse the outcome my <body class="" ?
glockops replied on at Permalink Reply
glockops
Instead of echoing it, assign it a variable. Also, to prevent problems with page defaults you should wrap it in an if statement that checks to see if you are setting defaults.

The example below assigns all the attributes to a single variable (note the .= instead of =). So you'll have a string to work with.

<?php
// Prevent this code from loading if defaults are being set
if(!$c->isMasterCollection()) {
// Load helper
$th = Loader::helper('text');
$parent = Page::getByID($c->getCollectionParentID());
// Remove the last part of this while statement if you ONLY want to avoid
// getting the attributes of the homepage.
while($parent->getCollectionID() > 1 && $parent->getCollectionParentID() > 1) {
   $myClasses .= $th->sanitizeFileSystem($parent->getCollectionName()) . ' ';   
// This will continue to add to the variable $myClasses until the while loop is exited.  It will output along the lines of 'greatgreatgrandchild greatgrandchild grandchild'
// The sanitizeFileSystem returns the attribute as lowercase with underscores, keep this in mind if using CSS.
   $parent = Page::getByID($parent->getCollectionParentID());
}// End while
}// End if master


Then in your body do something like
<body class="<?php echo $myClasses;?>">


Few words of caution, you need to make sure the attributes you retrieve are valid HTML. I've included concrete5's text helper in the code above. You might need to adjust depending on the attributes you retrieve. Documents here:http://www.concrete5.org/documentation/developers/helpers/text/... .
vincedelaking replied on at Permalink Reply
vincedelaking
Hi Daniel,

I will give it a go, seems not to assign anything yet.
But mabye I have to stay cool and take it line by line.