Stand With Ukraine. Stop Putin. Stop War.

The getResources snippet is actually quite easy when you know how to start. As everything though, it can be convenient to have someone point you in the right direction when starting something new.

What is getResources?

Some people call getResources the replacement for Ditto, and frankly, it is listed as an equivalent in the docs. But getResources is probably more flexible then that, especially when combined with other snippets such as getPage. This article will help you get started with a quick example of how to use getResources.

New for MODX 2.2: Articles!

As of MODX Revolution 2.2, you can also use the Articles plugin which is pretty much a one-click Blog install for MODX. Read more about Articles.

Requirements

Let's get going!

The getResources snippet takes a lot of different parameters as the documentation shows, but for now we'll only use a few of them. These are &tpl, &parents, &depth and &limit. MODX veterans (or at least anyone who has worked with snippets like Ditto and Wayfinder) will probably recognize what they do. In order, they specify a chunk to use as a template, the IDs of parent resources, the depth to search in and the number of resources to return.

This is my getResources call I place in the content of my category container page:

By doing this, you get all resources from within the resource it is being called from, only one level deep with a maximum of 10 resources being visible. The blogTpl chunk is as follows:

You can see we put each item in its own div with class blogPost, and create a link to our resource with the link tag. We're also using some output filters, for example "strtotime" and "date" to make nicely presented published dates. We also use a custom output filter, which is parsetags - one could just as easily use the toLinks snippet (part of tagLister) to create links to the tag detail pages. Furthermore we're also showing the count of comments, based on a thread identified by the parentid-resourceid - make sure that matches how you set up your comment threads in the Quip and QuipReply snippets!

Now, this was a real brief article - however there's many, many, many more to know about getResources - all of which you can find in the docs, and possible future follow-ups to this post.