We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36613
    • 328 Posts
    cristianb88 Reply #1, 8 years ago
    I want take the alement in another context, i have the id my snippets is this:

    $delimiter = $modx->getOption('delimiter', $scriptProperties, ',');
    $ids = explode($delimiter,$modx->getOption('ids', $scriptProperties));
    $output = '';
    
    
    foreach ($ids as $key => $value) {
      $resource = $modx->getObject('modResource',array('id' => $value));
    	
    
      if ($resource instanceof modResource) {
        //$output[] = $modx->getChunk($tpl,$resource->toArray());
        $output .= ' '.$resource->get('alias');
      }
    
    }
    
    return $output;


    But get option don't take the element in another context. For example i stay in context web i whant ave the alias of id in context eng. With getResource don't work.

    This question has been answered by BobRay. See the first response.

    • discuss.answer
      • 3749
      • 24,544 Posts
      I think the problem is not with your code, but with MODX permissions. My guess is that the user who is logged in does not have access to the other context via a context access ACL entry.

      If you're viewing the page from the Manager, remember that you're logged in to the Manager, but in the front end, you're the (anonymous) user and are not logged in unless you explicitly log in in the front end. If you use the Login snippet, remember to use the &contexts property so you'll be logged in multiple contexts.

      BTW, since ID is the primary key, you don't need an array for getObject():

      $resource = $modx->getObject('modResource', (int) $value);
        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