(713) 568-2763

ModX: Using ‘getResources’ to Make a Sortable Employee List

ModX: Using ‘getResources’ to Make a Sortable Employee List

Building Your First Website in MODx

Every now and then I get a request to make certain lists sortable. Maybe a law firm wants their employee list to be sortable by name or practice. Maybe it’s a production company and they want their films to be sortable by genre, year, and alphabetically. Databases are the usual way to go when sorting information is involved.

However, if you are a MODx user you can pull this off by simply using getResources. This is beneficial for a few reasons:

  1. You don’t know how to use databases
  2. The client plans on maintaining their site once you are done
  3. You simply don’t feel like dealing with databases for this project
  4. It’s fun trying something different every now and then

Back in the day, before MySQL was an integral part of everyday web building, you would simply create multiple pages with the same info but arranged differently. Then in your “sort” menu you would simply link to the proper page. The downside to this way is that if any information changes (like a phone number, position, a new employee, removing a former employee) you have to make that change on all pages you created.

The common method would be to simply put all that info in a database and then simply call on that info as you see fit. This is obviously the best and most versatile way of doing this. There really is no downside to using this method unless you simply have no idea how to use databases and don’t have time to learn.

MODx and getResources sits in the middle of these 2 methods. You are basically following the old school method, in that you are creating multiple pages for the various sorting states. However, if any edits are needed in the future you only have to make that change once.

Let’s run through this process using the employee example. I am going to assume that you are familiar with MODx and somewhat familiar with using Snippets like getResources or wayFinder.

 Create Your TVs and Build Out Your Employee Pages

So – if you have a root level page or directory called “Employees”. This will be the parent of all employees. All of the employee’s info will be marked up in the Resource Content area of these pages. This is what people will see when they click on the employee’s linked name. This area has nothing to do with what we will be doing. We will be using Template Variables (TVs) to set up each employee’s sorting ability.

You can use as many TVs as you like. You can sort a list 10 different ways if you prefer. In the spirit of keeping things simple I will talk about just a few. In this example I will tell you how to sort by position and also alphabetically. We are going to make one TV called “emp-position”. This will be the one that getResources will be looking for. You will also need to create a few more TVs to accommodate the template file for your results. (Assuming you want to display the name, picture, position, phone number, etc… in your results.)

On every employee resource you create you will need to fill these TVs out with their information. Do yourself a favor and alphabetize the order of the employee resources. Remember you can drag and drop resources in Revolution. It’s really easy to reorder your resources. Doing this will make things a bit easier in the end.

Now you will need to create and save a template chunk. We’ll call it “TPLemployees”. It might look something like this:


<a href=”/[[+alias]].html”><img src=”/images/[[+emp-img-sm]]” alt=”[[+emp-name]]” /></a>

<p><a href=”/[[+alias]].html”>[[+emp-name]]</a><br /><em>[[+emp-position]]</em><br />[[+emp-phone]] </a>


So given this, you will have needed to create the following TVs (and filled them out on each resource):

  1. emp-img-sm
  2. emp-name
  3. emp-position
  4. emp-phone

Most of your work is done at this point.

The Sorting Page(s)

Next you will need to create a hidden-from-menu resource. This will be your sorted results page. In the Resource Content of this page you are going to call up a list of employees that meet your sort criteria using a getResources snippet call. This call will look something like this:

[[getResources? &tpl=TPLemployees &parents=7 &includeTVs=1 &tvPrefix= &processTVs=1 &includeContent=1  &limit=50 &sortby=menuindex  &sortdir=ASC &tvFilters=Management]]

Now put this call on your root employee page:

[[!getResources? &parents=7 &tpl= TPLemployees &limit=50 &includeTVs=1 &tvPrefix= &processTVs=1 &includeContent=1 &sortby=menuindex  &sortdir=ASC]]

What’s Going On With All of This?

Let me explain what the getResources snippet is calling on:

  1. &tpl=TPLemployees is the template file you created. It provides the mark up of the basic info that you entered in all those TVs. This template applied to each resource under the “Employee” directory you created.
  2. &parents=7 tells getResources where to look for all of you employee resources (or pages). The 7 is the ID of the employee directory. This will most likely be a different ID for you.
  3. &includeTVs=1 &tvPrefix= &processTVs=1 &includeContent=1 are necessary in order for getResources to process TVs. It is not necessary to change any of these values for the sake of this tutorial. However, you should read up on them to fully understand them.
  4. &limit=50 simply limits your results to 50. This can be any number.
  5. &sortby=menuindex  &sortdir=ASC  sorts the employees in ascending order depending on the Menu Index of each resource. Good thing you alphabetized your employee resources!
  6. &tvFilters=Management This is the magic TV. It is saying to filter out all employees with a TV value of “Management”.  This value can be anything, as long as there is a TV with the same value in any of your employee resources.

View the Magic!

Now when you view your “employees.html”  page it should display all employees in ascending alphabetical order. Build a mini sorting nav so that those viewing your site can click a link and have the proper results served to them. So when they click on your “Management”  link, only employees labeled as “management” will be displayed. Add a “All Employees” link to you sorting nav on the sorted pages and point it back to the root employees page.

You’ve Scratched the Surface

This is a very basic run-through of this technique. With the right amount of TVs and properly labeled snippet calls, you can organize those resources any way you see fit. getResources is a very powerful and useful tool inside of MODx. Read more about it to see what else you can do. I hope this walkthrough was helpful. Understanding how to use add-ons like getResources or wayFinder will have you feeling and looking like a MODx pro!

Forthea’s mission is dedicated to helping clients achieve their full potential online through superior marketing that’s delivered with unsurpassed customer service and professionalism.


  1. Tom 5 years ago

    How could this be modified so a TV (checkboxes) would determine which categories a resource goes into so that clicking some sort of menu it would display only those resources which are in a particular category?? Like in a product catalog where a product fits into say, both clothing and shoes category, but we only want to type its info once??

    Thank you, Tom

  2. Lonnie Minter
    Lonnie Minter 5 years ago

    Hi Tom,
    So you want 1 product to show up in multiple categories? Keep in mind that this method isn’t as efficient or even as good as using a database. However, with some clever thinking you can do a lot with getResources.

    One way would to be to create a weblink with the other TV value(s). And then just point that weblink to the original product.

    A better solution would be to use checkboxes for your TV values.

    So instead of defining the categories with text in an input field, you could set the input type for your category TV with checkboxes.

    I haven’t actually done this, but in theory it should work.

    Here is a link with more details on TV input fields:


    I hope that helps.

  3. Tom 5 years ago

    You’re right, it’s not as efficient as a database but MODx doesn’t yet lend itself well to creating custom tables and the forms involved, since there would have to be at least two tables — products and categories. I’m not a developer/programmer. 🙂

    Your response is a good start for me though.

    Thank you, Tom

  4. Michiel Mussies 2 months ago

    A nice article, thank you.

    I did however notice that thexample has coding typo’s ( viewing in firefox, date october 2016)

    To be precise: all values in the snippet calls need to be hedged by backticks ( in my browser there appear none).
    For the image, the path ” /images/ ” should be left out as the current modx/getresources versions provide the full local path to the image.
    As all of the green snippet calls are in Italics, the quotation marks (href=”..” and alt=”…”) will throw errors when copied and pasted.

Leave a reply

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