I agree with Kongondo, this is probably wandering a bit too far off topic, but hopefully other people might find something of use here. It’s still kinda related - just an alternative to PHx.
Thanks Chuck - that’s much neater, I actually get switches now I’ve seen it in the context of this site! I had a go at something a bit different after seeing you returning the image path containing a variable, and finding a thread in the forum that showed ’getParent’ in context. I’d be interested to see if this is ’right’ - seems like it works ok!
$id=$modx->documentIdentifier;
$parent = $modx->documentObject['parent'];
$getAlias = $modx->getParent($id,'alias');
$parentAlias = $getAlias['alias'];
if ($parent=="0") {
$img = '[*alias*]';
} else {
$img = $parentAlias;
}
return "<img src=\"/veru/assets/images/$img.jpg\" alt=\"\" />";
If the document is in the top level/main menu (so parent is 0), use the document’s alias (image files are named home.jpg, news.jpg etc), otherwise if the document is a child, get the alias of its parent - so if it is a news post, use the same header image for the post as the container document (where the posts are listed with a Ditto call).
Thank you all for your help, I think I’m done now!
Dan