One of the first snippets I create/add to a new site is "getAliasArray".
Snippet name: [[getAliasArray]]
Description: makes arrays from parent folders
Snippet Code:
<?php
$query_children = $modx->db->query('
SELECT cat.id,cat.pagetitle,cat.alias
FROM '.$modx->getFullTableName('site_content').' AS cat
WHERE
cat.parent = "'.$parentFolder.'"
ORDER BY
cat.pagetitle
');
$arr_categories = array();
while ($row = $modx->db->getRow($query_children)) {
$arr_categories[] = $row['pagetitle']."==".$row['id'];
}
$output = implode("||",$arr_categories);
return $output;
?>
Then I can have a container folder like "Movie Genre (35)" with documents like "Horror", "Comedy", "Action", etc...
I can create a Template Variable [*genre*] select input type radio button and use this for the Input Option Values:
@EVAL return $modx->runSnippet('getAliasArray',array('parentFolder'=>'35'));
That will give a list of radio buttons with all the genres in my assigned template. That gives me an easy to maintain list of categories. Yes I could do it with a chunk, but here is were the good part come in.
I add my phx:docfield snippet.
Snippet name: [[phx:docfield]]
Description: get specified field from document (id)
Snippet Code:
<?php
$field = (strlen($options)>0) ? $options : 'pagetitle';
$docfield = $modx->getTemplateVarOutput(array($field), $output, 1);
return $docfield[$field];
?>
Now I can use this in my snippets to pull any field from the assigned category.
[+genre:docfield+]
[+genre:docfield=`introtext`+]
[+genre:docfield=`thumbnail`+]