I already use Modx for 3 years and I always used extras, mainly pdoTools and formit.
To be honest, since the first time I tried to play with Modx, I started also with extras. This is also encouraged by the Modx documentation itself.
Out of curiosity I have been looking around for the native modx snippets, but with little success.
What are the native snippets that would allow me to generate a list of resources, for instance?
Do I need to write a snippet for that if I don’t want to use any extra?
The objective is a very simple implementation of a basic site that would only require some pdoTools snippets (pdoResource, pdoMenu) and nothing more. The idea is to understand what Modx offers natively helping to reduce external dependencies and possible security flaws like seen previously with formit and gallery.
For example, the following snippet returns a list of published resources that are children of resource 23:
The snippet
<?php
/**
* listResources
*
* Usage example:
* [[listResources? &tpl=`myTpl`]]
*/
// grab the resources
$docs = $modx->getIterator('modResource',array(
'parent' => 23,
'published' => 1,
'hidemenu' => 0
));
// loop through results
foreach ($docs as $doc) {
// copy object fields into an array
// to make their values available inside your chunk via [[+fieldname]] as seen below
$fields = $doc->toArray();
// define the chunk used to display results. If none is specified, myTpl will be used
$tpl = $modx->getOption('tpl', $scriptProperties, 'myTpl');
$output[] = $modx->getChunk($tpl, $fields);
}
return implode('', $output);