We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • This snippet comes in handy for using getResource in a multi context setup. Thank you bwente for the help.

    Snippet: GetIDByAlias
    <?php
    $resources = $modx->getObject('modResource', array('alias' => $alias, 'context_key' => $modx->context->key));
    if ($resources == null) {
    return;
    } else {
      return $resources->get('id');
    }


    Usage in a getResource call:
    [[!getResources:default=`There are no items found.`? 
    	  &tpl=`yourTPL` 
    	  &parents=`[[GetIDByAlias? &alias=`your-alias-of-target-parent`]]`
    	  &context=`[[*context_key]]`
    	  &showHidden=`1`
    	  &depth=`1`
    	  &limit=`0`
    	  &includeTVs=`1` 
    	  &tvPrefix=`` 
    	  &processTVs=`1` 
    	  &includeContent=`0` 
    	  &sortby=`menuindex` 
      	  &sortdir=`ASC`
    	  ]]


    This can help you get the correct parent ID across context if you have a duplicate page on another context. Works great for getResource calls that you are calling parents other then the current document your on. [ed. note: orbitalalliance last edited this post 12 years, 7 months ago.]
      "Give a company a website, and they will be successful for now...
      Give a company a long-term web strategy, and they will be successful for a lifetime."

      Company Website: http://www.orbitalalliance.com
      Company Blog: http://www.orbitalalliance.com/blog
    • It might be a good idea for getResource to have a parameter for &parentsID= along with &parentsAlias= that would be helpful for multicontext sites where you don't know the parentID.
        "Give a company a website, and they will be successful for now...
        Give a company a long-term web strategy, and they will be successful for a lifetime."

        Company Website: http://www.orbitalalliance.com
        Company Blog: http://www.orbitalalliance.com/blog