We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 11055 ☆ A M B ☆
    • 3,112 Posts
    I believe I read a topic sometime ago, MODx core team has a suggestion that all add-ons (snippet, plugin, or even module) should always have their default values for the empty params snippet call.

    That’s why you will always find this kind of lines:
    $var = isset($var) ? $var : 'default value';
    


    getResources itself has them in it.
    The bug is that it uses isset() to an array, which will always be set as true although the value is empty.
      Rico
      Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
      MODx is great, but knowing how to use it well makes it perfect!

      www.virtudraft.com

      Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

      Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

      Maintainter/contributor of Babel

      Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.
      • 36541
      • 222 Posts
      Quote from: goldsky at Aug 18, 2010, 07:40 AM

      It’s been resolved by my debug above. Empty &parents will use page’s self ID, as it is intended to be from the beginning.

      I applied your patch to fix issues #10 and #12 in pull request 14.
        This is the web: the only thing you know about who will come is that you don't know who will come.
        • 11055 ☆ A M B ☆
        • 3,112 Posts
        @gadamiak,
        which patch?
        Splittingred has done the getChildIds() patching
        http://github.com/modxcms/revolution/commit/61b0deafeceab9daf55a23ef87d6a46b2c8175c8

        But thanks for the getResources request pulling wink
          Rico
          Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
          MODx is great, but knowing how to use it well makes it perfect!

          www.virtudraft.com

          Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

          Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

          Maintainter/contributor of Babel

          Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.
          • 36541
          • 222 Posts
          Quote from: goldsky at Sep 02, 2010, 02:53 AM

          @gadamiak,
          which patch?
          But thanks for the getResources request pulling wink

          I meant exactly that smiley However, I had to revert it, as your changes prevented to use empty/zero values for [tt]&tvPrefix[/tt], [tt]&parents[/tt] and [tt]&depth[/tt]. The source of the error with &parents unset was not use of [tt]isset[/tt] but the variable being initialized as empty in snippet properties.

          I provided another patch, which fixes it.
            This is the web: the only thing you know about who will come is that you don't know who will come.
            • 29626
            • 34 Posts
            Hello everyone,

            [Edit6]
            Config:

            • MODx Revolution 2.0.0-pl rev7212
            • MySQL version 5.1.31
            • PHP 5.2.13
            • getResources 1.1.0-pl
            [/Edit6]


            Same as goldsky, I have a mysql error after following documentation instructions:
            Snippet call:
            [[!getResources? &parents=`3` &limit=`20` &tpl=`blogListPost` &includeContent=`1`]]

            MySQL error:
            [2010-09-09 07:51:11] (ERROR @ /index.php) Error 42000 executing statement: Array ( [0] => 42000 [1] => 1064 [2] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '` ,7,8,9,10,11,12,13,14,15,16,17) AND (`modResource`.`context_key` IN ('web') O' at line 1 )


            I’ll test your workaround goldsky.
            Bye.

            [Edit]
            I’ve patched like goldsky suggested here but I have always a mysql error. Clearing site cache changes nothing as the snippet call is not cached.
            [2010-09-09 08:32:17] (ERROR @ /index.php) Error 42000 executing statement: Array ( [0] => 42000 [1] => 1064 [2] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '` ) AND (`modResource`.`context_key` IN ('web') OR EXISTS(SELECT 1 FROM `modx_c' at line 1 )

            [/Edit]

            [Edit2]
            Seems to fail around lines 117-120 of the snippet getResources:
            $criteria = $modx->newQuery('modResource', array(
                "`modResource`.`parent` IN (" . implode(',', $parents) . ")"
                ,"(`modResource`.`context_key` IN ({$context}) OR EXISTS(SELECT 1 FROM {$contextResourceTbl} `ctx` WHERE `ctx`.`resource` = `modResource`.`id` AND `ctx`.`context_key` IN ({$context})))"
            ));

            [/Edit2]

            [Edit3]
            Seems &parents is retrieving a backtick which is making trouble in snippet code...

            foreach ($parents as $p) {
              echo '<p>'.$p.'</p>';
            }
            die();
            

            Inserted just after getting parameters, before the getChildIds() call giving me in the output:
            3`

            Instead of:
            3


            [Edit4]
            Below a modified version of the snippet to handle $parents parameter correctly with printing out debugging stuff.
            Maybe it is not the better way to achieve this, but it seems to work as expected. No more mysql error.
            I didn’t understand why php explode way of making the job was adding a trailing backtick...
            <?php
            /**
             * getResources
             *
             * A general purpose Resource listing and summarization snippet for MODx 2.0.
             *
             * @author Jason Coward
             * @copyright Copyright 2010, Jason Coward
             * @version 1.1.0-pl - June 28, 2010
             *
             * TEMPLATES
             *
             * tpl - Name of a chunk serving as a resource template
             * [NOTE: if not provided, properties are dumped to output for each resource]
             *
             * tplOdd - (Opt) Name of a chunk serving as resource template for resources with an odd idx value
             * (see idx property)
             * tplFirst - (Opt) Name of a chunk serving as resource template for the first resource (see first
             * property)
             * tplLast - (Opt) Name of a chunk serving as resource template for the last resource (see last
             * property)
             * tpl_{n} - (Opt) Name of a chunk serving as resource template for the nth resource
             *
             * SELECTION
             *
             * parents - Comma-delimited list of ids serving as parents
             *
             * depth - (Opt) Integer value indicating depth to search for resources from each parent [default=10]
             *
             * tvFilters - (Opt) Delimited-list of TemplateVar values to filter resources by. Supports two
             * delimiters and two value search formats. THe first delimeter || represents a logical OR and the
             * primary grouping mechanism.  Within each group you can provide a comma-delimited list of values.
             * These values can be either tied to a specific TemplateVar by name, e.g. myTV==value, or just the
             * value, indicating you are searching for the value in any TemplateVar tied to the Resource. An
             * example would be &tvFilters=`filter2==one,filter1==bar%||filter1==foo`
             * [NOTE: filtering by values uses a LIKE query and % is considered a wildcard.]
             * [NOTE: this only looks at the raw value set for specific Resource, i. e. there must be a value
             * specifically set for the Resource and it is not evaluated.]
             *
             * where - (Opt) A JSON expression of criteria to build any additional where clauses from. An example would be
             * &where=`{{"alias:LIKE":"foo%", "OR:alias:LIKE":"%bar"},{"OR:pagetitle:=":"foobar", "AND:description:=":"raboof"}}`
             *
             * sortby - (Opt) Field to sort by [default=publishedon]
             * sortbyAlias - (Opt) Query alias for sortby field [default=]
             * sortbyEscaped - (Opt) Escapes the field name specified in sortby [default=0]
             * sortdir - (Opt) Order which to sort by [default=DESC]
             * limit - (Opt) Limits the number of resources returned [default=5]
             * offset - (Opt) An offset of resources returned by the criteria to skip [default=0]
             *
             * OPTIONS
             *
             * includeContent - (Opt) Indicates if the content of each resource should be returned in the
             * results [default=0]
             * includeTVs - (Opt) Indicates if TemplateVar values should be included in the properties available
             * to each resource template [default=0]
             * processTVs - (Opt) Indicates if TemplateVar values should be rendered as they would on the
             * resource being summarized [default=0]
             * tvPrefix - (Opt) The prefix for TemplateVar properties [default=tv.]
             * idx - (Opt) You can define the starting idx of the resources, which is an property that is
             * incremented as each resource is rendered [default=1]
             * first - (Opt) Define the idx which represents the first resource (see tplFirst) [default=1]
             * last - (Opt) Define the idx which represents the last resource (see tplLast) [default=# of
             * resources being summarized + first - 1]
             * outputSeparator - (Opt) An optional string to separate each tpl instance [default="\n"]
             *
             */
            $output = array();
            $outputSeparator = isset($outputSeparator) ? $outputSeparator : "\n";
            
            /* set default properties */
            $tpl = !empty($tpl) ? $tpl : '';
            $includeContent = !empty($includeContent) ? true : false;
            $includeTVs = !empty($includeTVs) ? true : false;
            $processTVs = !empty($processTVs) ? true : false;
            $tvPrefix = !empty($tvPrefix) ? $tvPrefix : 'tv.';
            //$parents = !empty($parents) ? explode(',', $parents) : array($modx->resource->get('id'));
            $depth = !empty($depth) ? (integer) $depth : 10;
            $children = array();
            
            /********* debug *********/
            echo "\$parents: ".$parents.'<br/>';
            /********* debug *********/
            
            $parents = !empty($parents) ? preg_split("/[,]+/", $parents) : array($modx->resource->get('id'));
            
            
            /********* debug *********/
            echo "\$modx->resource->get('id'): ".$modx->resource->get('id').'<br />';
            echo '<p>$parents listing:</p>';
            foreach ($parents as $p) {
              echo '<p>'.$p.'</p>';
            }
            //die();
            /********* debug *********/
            
            
            
            foreach ($parents as $parent) {
                $pchildren = $modx->getChildIds($parent, $depth);
                if (!empty($pchildren)) $children = array_merge($children, $pchildren);
            }
            
            /********* debug *********/
            echo '<p>$children listing:</p>';
            foreach ($children as $c) {
              echo '<p>'.$c.'</p>';
            }
            //die();
            /********* debug *********/
            
            
            
            if (!empty($children)) $parents = array_merge($parents, $children);
            
            $tvFilters = !empty($tvFilters) ? explode('||', $tvFilters) : array();
            
            $where = !empty($where) ? $modx->fromJSON($where) : array();
            $showUnpublished = !empty($showUnpublished) ? true : false;
            $showDeleted = !empty($showDeleted) ? true : false;
            
            $sortby = isset($sortby) ? $sortby : 'publishedon';
            $sortbyAlias = isset($sortbyAlias) ? $sortbyAlias : 'modResource';
            $sortbyEscaped = !empty($sortbyEscaped) ? true : false;
            if ($sortbyEscaped) $sortby = "`{$sortby}`";
            if (!empty($sortbyAlias)) $sortby = "`{$sortbyAlias}`.{$sortby}";
            $sortdir = isset($sortdir) ? $sortdir : 'DESC';
            $limit = isset($limit) ? (integer) $limit : 5;
            $offset = isset($offset) ? (integer) $offset : 0;
            $totalVar = !empty($totalVar) ? $totalVar : 'total';
            
            /* build query */
            $contextResourceTbl = $modx->getTableName('modContextResource');
            
            /* multiple context support */
            $modx->setLogTarget('ECHO');
            if (!empty($context)) {
                $context = explode(',',$context);
                $contexts = array();
                foreach ($context as $ctx) {
                    $contexts[] = $modx->quote($ctx);
                }
                $context = implode(',',$contexts);
                unset($contexts,$ctx);
            } else {
                $context = $modx->quote($modx->context->get('key'));
            }
            $criteria = $modx->newQuery('modResource', array(
                "`modResource`.`parent` IN (" . implode(',', $parents) . ")"
                ,"(`modResource`.`context_key` IN ({$context}) OR EXISTS(SELECT 1 FROM {$contextResourceTbl} `ctx` WHERE `ctx`.`resource` = `modResource`.`id` AND `ctx`.`context_key` IN ({$context})))"
            ));
            if (empty($showDeleted)) {
                $criteria->andCondition(array('deleted' => '0'));
            }
            if (empty($showUnpublished)) {
                $criteria->andCondition(array('published' => '1'));
            }
            if (empty($showHidden)) {
                $criteria->andCondition(array('hidemenu' => '0'));
            }
            if (!empty($hideContainers)) {
                $criteria->andCondition(array('isfolder' => '0'));
            }
            /* include/exclude resources, via &resources=`123,-456` prop */
            if (!empty($resources)) {
                $resources = explode(',',$resources);
                $include = array();
                $exclude = array();
                foreach ($resources as $resource) {
                    $resource = (int)$resource;
                    if ($resource == 0) continue;
                    if ($resource < 0) {
                        $exclude[] = abs($resource);
                    } else {
                        $include[] = $resource;
                    }
                }
                if (!empty($include)) {
                    $criteria->orCondition(array('modResource.id:IN' => $include),null,10);
                }
                if (!empty($exclude)) {
                    $criteria->andCondition(array('modResource.id NOT IN ('.implode(',',$exclude).')'));
                }
            }
            if (!empty($tvFilters)) {
                $tmplVarTbl = $modx->getTableName('modTemplateVar');
                $tmplVarResourceTbl = $modx->getTableName('modTemplateVarResource');
                $conditions = array();
                foreach ($tvFilters as $fGroup => $tvFilter) {
                    $filterGroup = count($tvFilters) > 1 ? $fGroup + 1 : 0;
                    $filters = explode(',', $tvFilter);
                    foreach ($filters as $filter) {
                        $f = explode('==', $filter);
                        if (count($f) == 2) {
                            $tvName = $modx->quote($f[0]);
                            $tvValue = $modx->quote($f[1]);
                            $conditions[$filterGroup][] = "EXISTS (SELECT 1 FROM {$tmplVarResourceTbl} `tvr` JOIN {$tmplVarTbl} `tv` ON `tvr`.`value` LIKE {$tvValue} AND `tv`.`name` = {$tvName} AND `tv`.`id` = `tvr`.`tmplvarid` WHERE `tvr`.`contentid` = `modResource`.`id`)";
                        } elseif (count($f) == 1) {
                            $tvValue = $modx->quote($f[0]);
                            $conditions[$filterGroup][] = "EXISTS (SELECT 1 FROM {$tmplVarResourceTbl} `tvr` JOIN {$tmplVarTbl} `tv` ON `tvr`.`value` LIKE {$tvValue} AND `tv`.`id` = `tvr`.`tmplvarid` WHERE `tvr`.`contentid` = `modResource`.`id`)";
                        }
                    }
                }
                if (!empty($conditions)) {
                    foreach ($conditions as $cGroup => $c) {
                        if ($cGroup > 0) {
                            $criteria->orCondition($c, null, $cGroup);
                        } else {
                            $criteria->andCondition($c);
                        }
                    }
                }
            }
            if (!empty($where)) {
                $criteria->where($where);
            }
            
            $total = $modx->getCount('modResource', $criteria);
            $modx->setPlaceholder($totalVar, $total);
            
            $criteria->sortby($sortby, $sortdir);
            if (!empty($limit)) $criteria->limit($limit, $offset);
            $columns = $includeContent ? '*' : $modx->getSelectColumns('modResource', 'modResource', '', array('content'), true);
            $criteria->select($columns);
            if (!empty($debug)) {
                $criteria->prepare();
                $modx->log(modX::LOG_LEVEL_ERROR, $criteria->toSQL());
            }
            $collection = $modx->getCollection('modResource', $criteria);
            
            $idx = !empty($idx) ? intval($idx) : 1;
            $first = empty($first) && $first !== '0' ? 1 : intval($first);
            $last = empty($last) ? (count($collection) + $idx - 1) : intval($last);
            
            /* include parseTpl */
            include_once $modx->getOption('getresources.core_path',null,$modx->getOption('core_path').'components/getresources/').'include.parsetpl.php';
            
            foreach ($collection as $resourceId => $resource) {
                $tvs = array();
                if (!empty($includeTVs)) {
                    $templateVars =& $resource->getMany('TemplateVars');
                    foreach ($templateVars as $tvId => $templateVar) {
                        $tvs[$tvPrefix . $templateVar->get('name')] = !empty($processTVs) ? $templateVar->renderOutput($resource->get('id')) : $templateVar->get('value');
                    }
                }
                $odd = ($idx & 1);
                $properties = array_merge(
                    $scriptProperties
                    ,array(
                        'idx' => $idx
                        ,'first' => $first
                        ,'last' => $last
                    )
                    ,$resource->toArray()
                    ,$tvs
                );
                $resourceTpl = '';
                $tplidx = 'tpl_' . $idx;
                if (!empty($$tplidx)) $resourceTpl = parseTpl($$tplidx, $properties);
                switch ($idx) {
                    case $first:
                        if (!empty($tplFirst)) $resourceTpl = parseTpl($tplFirst, $properties);
                        break;
                    case $last:
                        if (!empty($tplLast)) $resourceTpl = parseTpl($tplLast, $properties);
                        break;
                }
                if ($odd && empty($resourceTpl) && !empty($tplOdd)) $resourceTpl = parseTpl($tplOdd, $properties);
                if (!empty($tpl) && empty($resourceTpl)) $resourceTpl = parseTpl($tpl, $properties);
                if (empty($resourceTpl)) {
                    $chunk = $modx->newObject('modChunk');
                    $chunk->setCacheable(false);
                    $output[]= $chunk->process(array(), '<pre>' . print_r($properties, true) .'</pre>');
                } else {
                    $output[]= $resourceTpl;
                }
                $idx++;
            }
            
            /* output */
            $output = implode($outputSeparator, $output);
            $toPlaceholder = $modx->getOption('toPlaceholder',$scriptProperties,false);
            if (!empty($toPlaceholder)) {
                $modx->setPlaceholder($toPlaceholder,$output);
                return '';
            }
            return $output;
            ?>


            [/Edit4]

            [Edit5]
            If you want to see a listing, maybe telling to print all items whatever their menu status...
            [/Edit5]
              • 1441
              • 61 Posts
              Hey there.

              getResources is a pretty slick script thanks for all the great work.

              (got a problem though - which is probably my fault)

              Here’s the setup:

              [[!getResources? &parents=`78` &tpl=`tpl_slideshowImg` &tplLast=`tpl_slideshowImg_last` &processTVs=`1`]]


              tpl_slideshowImg Chunk
               '[[*hp_SlideshowImg]]': { caption: '[[+pagetitle]]', href: '[[++site_url]][[~[[+id]]]]' },


              tpl_slideshowImg_last Chunk
              '[[*hp_SlideshowImg]]': { caption: '[[+pagetitle]]', href: '[[++site_url]][[~[+id]]]]' }


              Note: There is only one result possible, and this is in a context entitled simply ’beta’

              Here’s the output: (censored slightly)

              [2010-09-09 07:11:24] (ERROR @ /home/xxxxx/public_html/core/model/modx/modtemplatevar.class.php : 422) PHP warning: DirectoryIterator::__construct(/home/xxxxx/public_html/core/model/modx/processors/element/tv/renders/beta/output/) [<a href='directoryiterator.--construct'>directoryiterator.--construct</a>]: failed to open dir: No such file or directory
              '': { caption: 'Image One', href: 'http://beta.xxxxx.org/system/homepage-slideshow/image-one' }, 

              ---

              And to be clear - [[*templateVariable]] is the proper tag syntax for a &tpl chunk, correct? (wasn’t clear in documentation - but I only looked for it because Ditto used placeholders.

              Thanks!!
                • 3749
                • 24,544 Posts
                The TV tag is correct. Try &tvPrefix=`` (with no space between the back-ticks) in the getResources tag. It assumes a prefix of "tv."

                If that doesn’t work, it could be a malformed entry in the TV or a permission problem (do front-end users have permission for the beta context?).
                  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
                  • 29626
                  • 34 Posts
                  Hello,

                  Adding tv sortbytvname functionnality to my previous post.
                  Working great with date sorting for blogs or other stuff.
                  It should be adapted to work whatever you will sort. I presume you could continue on this faster.
                  
                  <?php
                  /**
                   * getResources
                   *
                   * A general purpose Resource listing and summarization snippet for MODx 2.0.
                   *
                   * @author Jason Coward
                   * @copyright Copyright 2010, Jason Coward
                   * @version 1.1.0-pl - June 28, 2010
                   *
                   * TEMPLATES
                   *
                   * tpl - Name of a chunk serving as a resource template
                   * [NOTE: if not provided, properties are dumped to output for each resource]
                   *
                   * tplOdd - (Opt) Name of a chunk serving as resource template for resources with an odd idx value
                   * (see idx property)
                   * tplFirst - (Opt) Name of a chunk serving as resource template for the first resource (see first
                   * property)
                   * tplLast - (Opt) Name of a chunk serving as resource template for the last resource (see last
                   * property)
                   * tpl_{n} - (Opt) Name of a chunk serving as resource template for the nth resource
                   *
                   * SELECTION
                   *
                   * parents - Comma-delimited list of ids serving as parents
                   *
                   * depth - (Opt) Integer value indicating depth to search for resources from each parent [default=10]
                   *
                   * tvFilters - (Opt) Delimited-list of TemplateVar values to filter resources by. Supports two
                   * delimiters and two value search formats. THe first delimeter || represents a logical OR and the
                   * primary grouping mechanism.  Within each group you can provide a comma-delimited list of values.
                   * These values can be either tied to a specific TemplateVar by name, e.g. myTV==value, or just the
                   * value, indicating you are searching for the value in any TemplateVar tied to the Resource. An
                   * example would be &tvFilters=`filter2==one,filter1==bar%||filter1==foo`
                   * [NOTE: filtering by values uses a LIKE query and % is considered a wildcard.]
                   * [NOTE: this only looks at the raw value set for specific Resource, i. e. there must be a value
                   * specifically set for the Resource and it is not evaluated.]
                   *
                   * where - (Opt) A JSON expression of criteria to build any additional where clauses from. An example would be
                   * &where=`{{"alias:LIKE":"foo%", "OR:alias:LIKE":"%bar"},{"OR:pagetitle:=":"foobar", "AND:description:=":"raboof"}}`
                   *
                   * sortby - (Opt) Field to sort by [default=publishedon]
                   * sortbyAlias - (Opt) Query alias for sortby field [default=]
                   * sortbyEscaped - (Opt) Escapes the field name specified in sortby [default=0]
                   * sortdir - (Opt) Order which to sort by [default=DESC]
                   * limit - (Opt) Limits the number of resources returned [default=5]
                   * offset - (Opt) An offset of resources returned by the criteria to skip [default=0]
                   *
                   * *** Patched to add tv filtering
                   * @author Thierry BENDA - thbenda at gmail dot com - and people whom have given some elements to do the patch:
                   * splittingred: @see http://modxcms.com/forums/index.php/topic,52307.msg303199.html#msg303199
                   * b03tz :       @see http://modxcms.com/forums/index.php/topic,53436.msg309123.html#msg309123
                   *
                   * *** 
                   * sortbytvname - (Opt) Name of template variable to sort by
                   * *** 
                   *   
                   * OPTIONS
                   *
                   * includeContent - (Opt) Indicates if the content of each resource should be returned in the
                   * results [default=0]
                   * includeTVs - (Opt) Indicates if TemplateVar values should be included in the properties available
                   * to each resource template [default=0]
                   * processTVs - (Opt) Indicates if TemplateVar values should be rendered as they would on the
                   * resource being summarized [default=0]
                   * tvPrefix - (Opt) The prefix for TemplateVar properties [default=tv.]
                   * idx - (Opt) You can define the starting idx of the resources, which is an property that is
                   * incremented as each resource is rendered [default=1]
                   * first - (Opt) Define the idx which represents the first resource (see tplFirst) [default=1]
                   * last - (Opt) Define the idx which represents the last resource (see tplLast) [default=# of
                   * resources being summarized + first - 1]
                   * outputSeparator - (Opt) An optional string to separate each tpl instance [default="\n"]
                   *
                   */
                  
                  $output = array();
                  $outputSeparator = isset($outputSeparator) ? $outputSeparator : "\n";
                  
                  /* set default properties */
                  $tpl = !empty($tpl) ? $tpl : '';
                  $includeContent = !empty($includeContent) ? true : false;
                  $includeTVs = !empty($includeTVs) ? true : false;
                  $processTVs = !empty($processTVs) ? true : false;
                  $tvPrefix = !empty($tvPrefix) ? $tvPrefix : 'tv.';
                  //Below $parents is buggy because of trailing slash added when I do &parents=`3` as example.
                  //$parents = !empty($parents) ? explode(',', $parents) : array($modx->resource->get('id'));
                  //Correct way getting $parents value right now:
                  $parents = !empty($parents) ? preg_split("/[,]+/", $parents) : array($modx->resource->get('id'));
                  $depth = !empty($depth) ? (integer) $depth : 10;
                  $children = array();
                  
                  
                  foreach ($parents as $parent) {
                      $pchildren = $modx->getChildIds($parent, $depth);
                      if (!empty($pchildren)) $children = array_merge($children, $pchildren);
                  }
                  
                  
                  if (!empty($children)) $parents = array_merge($parents, $children);
                  
                  $tvFilters = !empty($tvFilters) ? explode('||', $tvFilters) : array();
                  
                  $where = !empty($where) ? $modx->fromJSON($where) : array();
                  $showUnpublished = !empty($showUnpublished) ? true : false;
                  $showDeleted = !empty($showDeleted) ? true : false;
                  
                  $sortby = isset($sortby) ? $sortby : 'publishedon';
                  $sortbyAlias = isset($sortbyAlias) ? $sortbyAlias : 'modResource';
                  $sortbyEscaped = !empty($sortbyEscaped) ? true : false;
                  if ($sortbyEscaped) $sortby = "`{$sortby}`";
                  if (!empty($sortbyAlias)) $sortby = "`{$sortbyAlias}`.{$sortby}";
                  $sortdir = isset($sortdir) ? $sortdir : 'DESC';
                  $limit = isset($limit) ? (integer) $limit : 5;
                  $offset = isset($offset) ? (integer) $offset : 0;
                  $totalVar = !empty($totalVar) ? $totalVar : 'total';
                  
                  
                  /* sorting by tv patch - use tv name and default options */
                  $sortbytvname = !empty($sortbytvname) ? $sortbytvname : '';
                  
                  
                  
                  
                  /* build query */
                  $contextResourceTbl = $modx->getTableName('modContextResource');
                  
                  /* multiple context support */
                  $modx->setLogTarget('ECHO');
                  if (!empty($context)) {
                      $context = explode(',',$context);
                      $contexts = array();
                      foreach ($context as $ctx) {
                          $contexts[] = $modx->quote($ctx);
                      }
                      $context = implode(',',$contexts);
                      unset($contexts,$ctx);
                  } else {
                      $context = $modx->quote($modx->context->get('key'));
                  }
                  $criteria = $modx->newQuery('modResource', array(
                      "`modResource`.`parent` IN (" . implode(',', $parents) . ")"
                      ,"(`modResource`.`context_key` IN ({$context}) OR EXISTS(SELECT 1 FROM {$contextResourceTbl} `ctx` WHERE `ctx`.`resource` = `modResource`.`id` AND `ctx`.`context_key` IN ({$context})))"
                  ));
                  
                  /* 
                    Make an inner join query on database 
                    @author thbenda
                    @see http://modxcms.com/forums/index.php?topic=52307.0
                  */
                  $criteria->innerJoin('modTemplateVarResource','TemplateVarResources');
                  $criteria->innerJoin('modTemplateVar','TemplateVar','`TemplateVar`.`id` = `TemplateVarResources`.`tmplvarid` AND `TemplateVar`.`name` = "'.$sortbytvname.'"');
                  /* End inner join stuff - some inner joined fields used below ($where statment) */
                  
                  if (empty($showDeleted)) {
                      $criteria->andCondition(array('deleted' => '0'));
                  }
                  if (empty($showUnpublished)) {
                      $criteria->andCondition(array('published' => '1'));
                  }
                  if (empty($showHidden)) {
                      $criteria->andCondition(array('hidemenu' => '0'));
                  }
                  if (!empty($hideContainers)) {
                      $criteria->andCondition(array('isfolder' => '0'));
                  }
                  /* include/exclude resources, via &resources=`123,-456` prop */
                  if (!empty($resources)) {
                      $resources = explode(',',$resources);
                      $include = array();
                      $exclude = array();
                      foreach ($resources as $resource) {
                          $resource = (int)$resource;
                          if ($resource == 0) continue;
                          if ($resource < 0) {
                              $exclude[] = abs($resource);
                          } else {
                              $include[] = $resource;
                          }
                      }
                      if (!empty($include)) {
                          $criteria->orCondition(array('modResource.id:IN' => $include),null,10);
                      }
                      if (!empty($exclude)) {
                          $criteria->andCondition(array('modResource.id NOT IN ('.implode(',',$exclude).')'));
                      }
                  }
                  if (!empty($tvFilters)) {
                      $tmplVarTbl = $modx->getTableName('modTemplateVar');
                      $tmplVarResourceTbl = $modx->getTableName('modTemplateVarResource');
                      $conditions = array();
                      foreach ($tvFilters as $fGroup => $tvFilter) {
                          $filterGroup = count($tvFilters) > 1 ? $fGroup + 1 : 0;
                          $filters = explode(',', $tvFilter);
                          foreach ($filters as $filter) {
                              $f = explode('==', $filter);
                              if (count($f) == 2) {
                                  $tvName = $modx->quote($f[0]);
                                  $tvValue = $modx->quote($f[1]);
                                  $conditions[$filterGroup][] = "EXISTS (SELECT 1 FROM {$tmplVarResourceTbl} `tvr` JOIN {$tmplVarTbl} `tv` ON `tvr`.`value` LIKE {$tvValue} AND `tv`.`name` = {$tvName} AND `tv`.`id` = `tvr`.`tmplvarid` WHERE `tvr`.`contentid` = `modResource`.`id`)";
                              } elseif (count($f) == 1) {
                                  $tvValue = $modx->quote($f[0]);
                                  $conditions[$filterGroup][] = "EXISTS (SELECT 1 FROM {$tmplVarResourceTbl} `tvr` JOIN {$tmplVarTbl} `tv` ON `tvr`.`value` LIKE {$tvValue} AND `tv`.`id` = `tvr`.`tmplvarid` WHERE `tvr`.`contentid` = `modResource`.`id`)";
                              }
                          }
                      }
                      if (!empty($conditions)) {
                          foreach ($conditions as $cGroup => $c) {
                              if ($cGroup > 0) {
                                  $criteria->orCondition($c, null, $cGroup);
                              } else {
                                  $criteria->andCondition($c);
                              }
                          }
                      }
                  }
                  
                  if (!empty($where)) {
                      /* patched to allow sorting (here - by date) */
                      $now = strftime('%Y-%m-%d %H:%M:%S',time());
                      $where['TemplateVarResources.value:<'] = $now;
                      $criteria->where($where);
                  }
                  
                  $total = $modx->getCount('modResource', $criteria);
                  $modx->setPlaceholder($totalVar, $total);
                  
                  
                  $criteria->sortby($sortby, $sortdir);
                  $criteria->sortby('`TemplateVarResources`.`value`', $sortdir);
                  
                  if (!empty($limit)) $criteria->limit($limit, $offset);
                  $columns = $includeContent ? '*' : $modx->getSelectColumns('modResource', 'modResource', '', array('content'), true);
                  $criteria->select($columns);
                  if (!empty($debug)) {
                      $criteria->prepare();
                      $modx->log(modX::LOG_LEVEL_ERROR, $criteria->toSQL());
                  }
                  
                  
                  $collection = $modx->getCollection('modResource', $criteria);
                  
                  
                  
                  
                  $idx = !empty($idx) ? intval($idx) : 1;
                  $first = empty($first) && $first !== '0' ? 1 : intval($first);
                  $last = empty($last) ? (count($collection) + $idx - 1) : intval($last);
                  
                  /* include parseTpl */
                  include_once $modx->getOption('getresources.core_path',null,$modx->getOption('core_path').'components/getresources/').'include.parsetpl.php';
                  
                  
                  
                  foreach ($collection as $resourceId => $resource) {
                      $tvs = array();
                      if (!empty($includeTVs)) {
                          $templateVars =& $resource->getMany('TemplateVars');
                          foreach ($templateVars as $tvId => $templateVar) {
                              $tvs[$tvPrefix . $templateVar->get('name')] = !empty($processTVs) ? $templateVar->renderOutput($resource->get('id')) : $templateVar->get('value');
                          }
                      }
                      $odd = ($idx & 1);
                      $properties = array_merge(
                          $scriptProperties
                          ,array(
                              'idx' => $idx
                              ,'first' => $first
                              ,'last' => $last
                          )
                          ,$resource->toArray()
                          ,$tvs
                      );
                      $resourceTpl = '';
                      $tplidx = 'tpl_' . $idx;
                      if (!empty($$tplidx)) $resourceTpl = parseTpl($$tplidx, $properties);
                      switch ($idx) {
                          case $first:
                              if (!empty($tplFirst)) $resourceTpl = parseTpl($tplFirst, $properties);
                              break;
                          case $last:
                              if (!empty($tplLast)) $resourceTpl = parseTpl($tplLast, $properties);
                              break;
                      }
                      if ($odd && empty($resourceTpl) && !empty($tplOdd)) $resourceTpl = parseTpl($tplOdd, $properties);
                      if (!empty($tpl) && empty($resourceTpl)) $resourceTpl = parseTpl($tpl, $properties);
                      if (empty($resourceTpl)) {
                          $chunk = $modx->newObject('modChunk');
                          $chunk->setCacheable(false);
                          $output[]= $chunk->process(array(), '<pre>' . print_r($properties, true) .'</pre>');
                      } else {
                          $output[]= $resourceTpl;
                      }
                      
                      $idx++;
                  }
                  
                  /* output */
                  $output = implode($outputSeparator, $output);
                  $toPlaceholder = $modx->getOption('toPlaceholder',$scriptProperties,false);
                  if (!empty($toPlaceholder)) {
                      $modx->setPlaceholder($toPlaceholder,$output);
                      return '';
                  }
                  return $output;
                  ?>
                  


                  An example of snippet call:
                  [[!getPage? 
                     &elementClass=`modSnippet`
                     &element=`getResourcesCustom`
                  
                     &parents=`3`
                     &depth=`2`
                     &limit=`5`
                     &showHidden=`1`
                  
                     &sortdir=`DESC`
                     &pageVarKey=`page`
                  
                     &sortbytvname=`blogDateArticle`
                  
                     &includeTVs=`1`
                     &includeContent=`1`
                  
                     &tpl=`blogListPost`
                     &pageFirstTpl=`getPageFirstTpl`
                     &pageLastTpl=`getPageLastTpl`
                     &pagePrevTpl=`getPagePrevTpl`
                     &pageNextTpl=`getPageNextTpl`
                     
                  ]]
                  

                  Only one parameter more, the name of the tv you want to use for sorting.
                  &sortbytvname=`blogDateArticle`



                  And you’ll have something working like a charm.
                    • 1441
                    • 61 Posts
                    @ BobRay

                    Thanks for the pointer - however I still seem to have the same problem - even with my modified tag (thanks for the pointer Btw:
                    [[!getResources? &parents=`78` &tvPrefix=`` &tpl=`tpl_slideshowImg` &tplLast=`tpl_slideshowImg_last` &processTVs=`1`]]


                    I haven’t got any page, context or anything controlled at the moment (regarding your note about security) - but for what it’s worth - I followed that path, and there isn’t even such a folder as /beta. I originally created the context by duplicating pre-existing one. Could this be a Revo Bug?

                    Thanks again for your kind help.

                    UPDATE: now, it seems that I’m not getting a php error - the TV just doesn’t show up. If it means anything this particular TV produces the path to an image. (i.e. assets/files/images/example.jpg)
                      • 3749
                      • 24,544 Posts
                      A couple of things to try:

                      Look at the source of the page an see if there’s anything where the TV would go.

                      Try doing the same thing in the web context and see if that works. That will tell you if the context itself is an issue.

                      BTW, contexts are an abstraction so there would never be a folder named for one unless you created it.
                        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