We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26575
    • 57 Posts
    Hey,

    I’m using the getResources snippet in modx revlution (2.0-pl) and i want to get all resources with a spevial tv value of all contexts.
    so i’am calling:
    $output = $modx->runSnippet('getResources',array(
    	'parents' => '0',
    	'limit' => '20',
       'tvFilters' => $field.'=='.$current_internationalkey  //'tvFilters' => 'internationalkey==ueber_uns'
    ));
    return $output;


    But I’m only getting the ressource of the same context, where the snippet is placed.
    Has anybody an idea what i can do?

      christian seel - www.christianseel.com
      web developer & designer at chsmedien.de
      twitter: @christianseel / @chsmedien
      • 4172
      • 5,888 Posts
      there is a parameter &context, which you can try to set.

      Or you can try to hack getresources a little like that:

      /* build query */
      
      $carray=array(
          'deleted' => '0'
          ,'published' => '1'
          ,"`modResource`.`parent` IN (" . implode(',', $parents) . ")"
      );
      
      if ($context <>'all'){
      $contextResourceTbl = $modx->getTableName('modContextResource');
      $context = empty($context) ? $modx->quote($modx->context->get('key')) : $modx->quote($context);	
      $carray[] = "(`modResource`.`context_key` = {$context} OR EXISTS(SELECT 1 FROM {$contextResourceTbl} `ctx` WHERE `ctx`.`resource` = `modResource`.`id` AND `ctx`.`context_key` = {$context}))";
      }
      
      $criteria = $modx->newQuery('modResource',$carray);
      if (empty($showHidden)) {
          $criteria->andCondition(array('hidemenu' => '0'));
      }


      and use &context=`all`. Did not test it, but perhaps this can do what you want.
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 26575
        • 57 Posts
        Great! I forgot to lock inside the code...thanks for the hint.


        I have another little problem now with getResources:

        when I generate a link to a ressource inside the default web-context (1st context with my main domain) from anothercontext (2nd context with subdomain), the base_url(?) of the link is wrong.

        example:
        [[~[[+id]]]]

        generates in my 2nd context (subdomain) with an ID of my 1st context (main domain) this link:
        http://mysubdomain.domain.com/jobs.html (wrong)
        it should be http://www.domain.com/jobs.html

        In the other direction the links are correct.
          christian seel - www.christianseel.com
          web developer & designer at chsmedien.de
          twitter: @christianseel / @chsmedien
          • 28215
          • 4,149 Posts
          try [[~[[+id]]? &scheme=`full`]] and see if that works; might not.
            shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
            • 26575
            • 57 Posts
            does not work! only adds the full absolute path to the link of the same context...
              christian seel - www.christianseel.com
              web developer & designer at chsmedien.de
              twitter: @christianseel / @chsmedien
            • Sounds like you do not have your site_url or base_url properly configured in your subdomain context.
                • 26575
                • 57 Posts
                Well, I got it.
                But it was not a missing setting in my subdomain context. The solution was to set the site_url in the web-context settings.
                I thought modx will get this setting from the global settings...
                Thanks for your help!
                  christian seel - www.christianseel.com
                  web developer & designer at chsmedien.de
                  twitter: @christianseel / @chsmedien
                  • 26575
                  • 57 Posts
                  One more thing:

                  I’m searching for a way to get the context-description for each of the documents from the getResources snippet as placeholder for my tpl. Has someone a hint?
                    christian seel - www.christianseel.com
                    web developer & designer at chsmedien.de
                    twitter: @christianseel / @chsmedien
                  • Quote from: Seel-Media at Jul 23, 2010, 04:34 PM

                    But it was not a missing setting in my subdomain context. The solution was to set the site_url in the web-context settings.
                    I thought modx will get this setting from the global settings...
                    No, the default behavior is to use whatever is reported by the HTTP_HOST headers and such; consider a site that responds to multiple domains in a single context (e.g. an internal URL vs. an external one). In order to do cross-context linking properly, you need to specifically define this for all Contexts from which you will be generating links in other Contexts.

                    Quote from: Seel-Media at Jul 23, 2010, 05:00 PM

                    I’m searching for a way to get the context-description for each of the documents from the getResources snippet as placeholder for my tpl. Has someone a hint?
                    This isn’t available, but you can easily author a quick snippet to get this, e.g.
                    <?php
                    // Snippet: getContextDescription
                    $output = '';
                    if (!empty($context)) {
                        $object = $modx->getObject('modContext', $context);
                        if ($object) {
                            $output = $object->get('description');
                        }
                    }
                    return $output;
                    ?>


                    Then in your tpl just use:
                    [[getContextDescription? &context=`[[+context_key]]`]]
                      • 26575
                      • 57 Posts
                      Great! Thanks for your support jason!
                        christian seel - www.christianseel.com
                        web developer & designer at chsmedien.de
                        twitter: @christianseel / @chsmedien