Hi there,
I'm still learning to write snippets, and I was hoping to get a bit of critique.
Very simple, I want to efficiently collect the basic fields of mod_resource's by 'id' and also one of the tpl vars which is associated w/ each - called 'image' in this case.
Here's snippet code:
// init output
$output = '';
// get collection of res. by id's (set in snpptcall)
$resourceCollection = $modx->getCollection(
'modResource',
"`id` IN (" .$bannerItems. ")"
);
// loop through collection, array-ify each...
foreach($resourceCollection as $resource){
$fields = $resource->toArray();
// ... and add tv "image" to each arrayed resource
$fields['image'] = $resource->getTVValue('image');
// add chunk call to output for each arrayed resource
$output .= $modx->getChunk('banner.item',$fields);
};
// return output
return $output;
So, it works. And I suppose that in many cases that's the important thing. But I would like to know if this is also a decent snippet, and not just a working snippet. In particular, I'd like to know if it's going to give me a worthwhile performance boost over getResources? Is it worth the custom snippet?
Thanks for any comments you can give.
-gabriel
[ed. note: unsub777 last edited this post 12 years, 5 months ago.]