We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34183
    • 23 Posts
    What’s the use case??
    We are deploying multiple sites and generating resources programmatically, so we can’t rely on a resource ID as the parent in a getResources call, however, we do have control over the alias. We can’t always use [[UltimateParent]] so...

    I made a tiny snippet called [[GetIDByAlias]]:
    <?php
    $resources = $modx->getObject(modResource, array('alias' => $alias ));
    echo $resources->get('id');
    ?>


    Call:
    [[GetIDByAlias? &alias=`myAliasName`]]


    This just returns the resource id. I used it as such:
    [[!getResources? &parents=`[[GetIDByAlias? &alias=`myAliasName`]]`]]


    Hopefully this will help someone searching for something similar.
      • 34183
      • 23 Posts
      added a little error checking:

      $resources = $modx->getObject(modResource, array('alias' => $alias ));
      if ($resources != null) echo $resources->get('id');