We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21872
    • 95 Posts
    It would be useful to have things like [[*parent:pagetitle]] available ... is there something like that? Admittedly, it’s an easy snippet to add, so not a super high priority as a built in, but it could be handy.
      • 3749
      • 24,544 Posts
      If you use it a lot, you could make it a custom output modifier (but watch out, resources at the root don’t have a parent with a pagetitle, so trying to get it would throw a PHP error).

      <?php
      /* GetParentName snippet */
      
      if ($resource->get('parent')) {
      $parent = $modx->getObject('modResource',$modx->resource->get('parent'));
          return $parent->get('pagetitle');
      } else {
          return 'site-root';
      }
        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
        • 21872
        • 95 Posts
        Thanks, that’s essentially what I’ve done, except mine looks like this:

        if ($input) {
        $pageTitle = $modx->getObject('modResource', $input);
        return $pageTitle->get('pagetitle');
        } else {
        return " ";
        
        /* use
        [[*parent:pagetitle]]
        or
        [[~10:pagetitle]]
        or
        [[pagetitle?input=`123`]]
        or, perhaps most interestingly
        [[+placeholder:pagetitle]]
        */
        }
          • 3749
          • 24,544 Posts
          Looks good, although I wouldn’t use pagetitle for the name of the snippet/modifier. It makes me uneasy to use the name of a resource field for an element or variable name and there might be an output modifier with that name someday that does something else.
            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