I was looking for a way to save the manager/user from having to manually update a listbox TV to include new chunks as and when they came along.
Back then I couldn’t find anything so I left thing’s as they were. Yesterday I came across
Creating TV based chunks in the wiki, so using that SQL call this is what I have:
Create a snippet which this inside:
<?php
$sql='SELECT chunk.* FROM modx_site_htmlsnippets AS chunk INNER JOIN modx_categories AS category ON chunk.category = category.id WHERE category.category IN ("'.$category.'")ORDER BY name';
$result = $modx->dbQuery($sql);
$catArray = array();
for($i=0;$i<@$modx->recordCount($result);$i++) {
array_push($catArray,@$modx->fetchRow($result));
}
foreach ($catArray as $arrayName => $arrayDescr){
$form_output .= $arrayDescr['description']."=={{".$arrayDescr['name']."}}||";
}
return $form_output;
?>
then in the TV you want to use this in the "Input Option Values field":
@EVAL return $modx->runSnippet('NameOfSnippet',array('category'=>'Name of Category'));
Select Input Type: ListBox and you are good to go.
The only thing I don’t get from the Wiki is:
Change LeftChunks to whatever you name the Chunk category to, or you can also select from multiple chunk categories by separating their names with commas.
I’ve tried
@EVAL return $modx->runSnippet('nameOfSnippet',array('category'=>'OpeningTimeChunks','category'=>'Another category'));
which only returns the second category and
@EVAL return $modx->runSnippet('nameOfSnippet',array('category'=>'OpeningTimeChunks','Another category'));
which only returns the first. This is tested using the code from the WIki, not my nastiness
Another thing I’m not too sure about is the SQL, it seems to be retrieving an awful lot of data there. Maybe I could do away with some of that, but beyonds as how I don’t know what on earth chunk. before some of the bits in the call do...I left it
Cheers,
Taff