I want to display the current parent document page title on all of the child documents of a parent in my template.
For example, if I have a primary navigation of "Home, Company, Products, Contact", and for the "Company" parent document, I have child documents of "About Us", "Our History", "Our Locations". Laid out, it would be:
Home
Company
> About Us
> Our History
> Our Locations
Products
Contact
I want to place in my template a snippet call to include the name "Company" on each of the pages "About Us", "Our History", and "Our Locations." When you were on Products (or Products Children) it would say "Products". Same with Contact, it would say "Contact". If there were children documents of the children documents it would still say the parent page title name in the snippet.
Is there is a snippet that would do this? If so, what is the snippet name and how do I call it in the template?
-
MODX Staff
- 12,272 Posts
DropMenu is really what it looks like in your layout above.
Ryan Thrash, MODX Co-Founder
Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
-
☆ A M B ☆
- 24,524 Posts
Maybe one of the page trail or breadcrumb snippets would also be useful?
-
☆ A M B ☆
- 24,524 Posts
Try this:
//-- Modified version of sottwell's UltimateParent snippet
//-- Outputs pagetitle of the Ultimate Parent doc
$id = $modx->documentIdentifier;
$pid = $modx->getParent($id,1,"id,pagetitle");
if($pid['id'] == 0) { return $modx->documentObject['pagetitle']; }
while ($pid['id'] != 0) {
$id = $pid['id'];
$pagetitle = $pid['pagetitle'];
$pid = $modx->getParent($id,1,"id,pagetitle");
}
return $pagetitle;
Yes, Susan, that worked quite nicely. Thank you!
Original question/problem solved. If you have more questions please start a new thread.
regards,
zi