Hi guys,
I’d like to access properties about the parent of a page in the template. I’ve discovered [[*parent]], which kinda gives a link to the parent. However, it’s not perfect, as instead of getting "/parent/child", I get "/parent/4". Is there a way to get the correctly resolved SEO URL for the parent? Can I also get properties of the parent? For instance [[*parent.description]] or [[*parent.someTV]]???
Thanks loads,
Lee
In case you want a snippet (which would be somewhat faster and more efficient), this should help:
<?php
$parentObj = $modx->getObject('modResource', $modx->resource->get('parent'));
$parentPagetitle = $parentObj->get('pagetitle');
$parentPublished = $parentObj->get('published');
// etc. for any field except content, use $parentObj->getContent() for that.
You can set placeholders for all parent fields with this (though it may be slower because it will set a bunch of placeholders you don’t need):
$modx->toPlaceholders($parentObj->toArray(), 'parent');
With the above line, the placeholders will have the prefix ’parent.’ to avoid collisions, so they’d show with:
[[+parent.pagetitle]]
[[+parent.content]]
etc.
I love getting these kind of tips from you guys on the dev team. That looks super efficient... cheers Jason!
I can’t believe I didn’t think of getOne(’Parent’). I’ve written about it dozens of times. I guess I need more sleep.