We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32391
    • 37 Posts
    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’)
      • 32391
      • 37 Posts
      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!
        • 28042 ☆ 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’].
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 32391
          • 37 Posts
          Thanks!
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            FIY, the document’s parent is stored in the "parent" field in the site_content table.
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 3749
              • 24,544 Posts
              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;
              ?>

                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting