Hi Everyone,
I was looking for a way to find a document’s path relative to the site url. So, for example, I have a document 3 deep and I want to prepend it’s parent’s alias’s, and pass it through a chunk for display. I somehow had this working, but then the MODx install got corrupted and I had to do this portion over. So, I’m guessing there is an easier way to do this.
I created a snippet to find documents based on a TV and have the results gathered through this while loop:
while($row = $modx->db->getRow( $results )) {
$alias = $row['alias'];
$pagetitle = $row['pagetitle'];
$path = getDocumentPath($alias,$row['id']);
$output .= $modx->parseChunk($tpl, array('alias' => $alias, 'pagetitle' => $pagetitle), '[+', '+]' );
}
Here is the getDocumentPath function:
function getDocumentPath(&$path,$docId, $separator = '/') {
global $modx;
$parent = $modx->getParent($docId, 1, 'alias,parent,id');
$path = $parent['alias'] . $separator . $path;
if($parent['parent'] != 0) {
if(getDocumentPath($path,$parent['id'])) return true;
}
else {
return true;
}
}
I was just curious if this was already built into MODx, if something out there already exists to do this (non-core MODx), or if someone else needs a similar function to do the same thing.
Cheers,
Shawn