Update : GetParentTitle becomes GetParentField.
More and more improvment thanks to the help of mrcou.
Now GetParentField can be used to call any tv you want of the Parent.
Snippet code here (and file attached)
$id=(!isset($id)) ? $modx->documentObject['id'] : $id;
if($id==0)return;
$target=(!isset($target)) ? 'pagetitle' : $target;
$parent = $modx->getParent($id,1,$target);
$parent = $parent[$target];
return $parent;
To call the snippet, juste use [!GetParentField? &id=`[*id*]`!] (to get the title) or [!GetParentField? &target=`introtext` &id=`[*id*]`!] to get the intro (you can now specify the tv you want to display with the &target variable.
Original post
Hi,
Thx to Heliotrope, I managed to build my first snippet, called GetTitleParent
Here is the code :
$parent = $modx->getParent($id,1,'pagetitle');
$parent = $parent['pagetitle'];
return $parent;
I call the snippet in a chunk :
<a href="[~[*parent*]~]">[!GetTitleParent? &id=`[*parent*]`!]</a>
The nav is like this : Folder 1 (id=13) > Folder 2 (14) > Document A (5)
But, and that’s the reason why I’m posting now, there’s something strange.
As I call the chunck in document A, the id of the parent should be 14, right ?
[~[*parent*]~] builds the good link to Folder 2 but
[!GetTitleParent? &id=`[*parent*]`!] build a text with id 13 so with the parent of the parent of document A.
Am I clear ?
Don’t know how to resolve it. Thx for help