Created
November 25, 2010 09:51
-
-
Save rtripault/715140 to your computer and use it in GitHub Desktop.
MODx Revolution snippet to list resources of a given parent in order to output it in Option Values of a TV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* build a query to get Resources with a given parent that are published and not deleted */ | |
$query = $modx->newQuery('modResource', array('parent' => 147, 'deleted' => false, 'published' => true)); | |
/* to optimize, you can select only the columns you need */ | |
// $query->select($modx->getSelectColumns('modResource', 'modResource', '', array('id', 'class_key', 'context_key'))); | |
/* get the modResource objects with the given parent */ | |
$children = $modx->getCollection('modResource', $query); | |
/* loop through the children and push the id onto $resourceIds */ | |
$resourceIds = ""; | |
$i=0; | |
foreach ($children as $child) { | |
if ($i!=0) { | |
$resourceIds .= "||"; | |
} | |
$resourceIds .= $child->get('pagetitle'); | |
$resourceIds .= "=="; | |
$resourceIds .= $child->get('id'); | |
$i++; | |
} | |
return $resourceIds; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@EVAL return $modx->runSnippet('getAside'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Don't forget to set Ouput Type as Delimiter «,» in order to be able to use the ouput in a getResources call |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
FWIW:
will get the same data without a single query being executed. Much more efficient.