MODX User Report II

In the previous article, we produced a list of resources created by the cuMODX logorrent user. In this one, we’ll send a property in the snippet tag to tell the snippet which of the user-related fields we want to use for our search.

The Snippet Tag

With the added property, our snippet tag will look like this::

[code language=”html”]
[[UserResourceReport? &searchField=`createdby`]]


The Tpl Chunk

The Tpl chunk (ResourceReportTpl) will take this form:

[code language=”html”]
<p class="page_field">Description: [[+description]]</p>
<p class="page_field">Summary: [[+summary]]</p>


If you want include TVs in the output, you could modify the code to get them, but doing so is fairly complex, so it’s best to just use getResources (or better yet, pdoResources), which will set them for you.


The Code

Here’s the code of our snippet, modified to use the &searchField property. We’ll set createdby as the default in case the user forgets to include the &searchField property.

[code language=”php”]
/* UserResourceReport snippet */
$userId = $modx->user->get(‘id’);
$searchField = $modx->getOption(‘searchField’, $scriptProperties, ‘createdby’);
$docs = $modx->getCollection(‘modResource’, array($searchField => $userId));
$output = ”;

foreach($docs as $doc) {
$fields = $doc->toArray();
$output .= $modx->getChunk(‘ResourceReportTpl’, $fields);

return $output;

As you can see, The addition of the new property doesn’t change our snippet very much.


A Complete Report

Now that our snippet will get resources based on any field, we can produce a complete report for the user by doing something like this:

[code language=”html”]
<h2>Resources You’ve Created</h2>
[[!UserResourceReport? &searchField=`createdby`]]

<h2>Resources You’ve Published</h2>
[[!UserResourceReport? &searchField=`publishedby`]]

<h2>Resources You’ve Edited</h2>
[[!UserResourceReport? &searchField=`publishedby`]]


Coming Up

Our list of resources will generally be in the order that the resources were created. You might well want to sort them (usually by pagetitle). We’ll see how to do that in the next article.


For more information on how to use MODX to create a web site, see my web site Bob’s Guides, or
better yet, buy my book: MODX: The Official Guide.

Looking for quality MODX Web Hosting? Look no further than Arvixe Web Hosting!

Tags: , , | Posted under MODX, MODX | RSS 2.0

Author Spotlight

Bob Ray

Bob Ray is the author of MODX: The Official Guide and over 30 MODX add-on components. He hosts Bob's Guides, a source of valuable information for MODX users, and has been very active in the MODX Forums with over 19,000 posts.

Leave a Reply

Your email address will not be published. Required fields are marked *