Hi there,
I want to display some images on certain pages, specifically pages that have a certain parent page.
So something like
if (parent_page == ’some page title’)
Sorry, I accidently posted without finishing.
So as I was saying..
if (parent_page == ’some page title’) {
do something...
}
my question is how do I find the pareent page?
I haven’t got phx installed, so if the solution requires it please say.
Thanks in advance!
-
☆ A M B ☆
- 24,524 Posts
You should use the parent document’s ID rather than its title; you can get the parent of the current document in HTML with the MODx [*parent*] tags, or in PHP code with $modx->documentObject[’parent’].
-
☆ A M B ☆
- 24,524 Posts
FIY, the document’s parent is stored in the "parent" field in the site_content table.
You can send the parent ID as a parameter in your snippet call like this:
[!SnippetName? &parentID=`[*parent*]`!]
In your snippet, it will be available as $parentID, so the snippet might look something like this:
<?php
$output='';
switch ($parentID) {
case: '3') {
$output = 'Parent is three';
break;
case: '5':
$output = 'Parent is five';
break;
default:
$output = 'unknown parent';
break;
}
return $output;
?>