ModxI have been developing a new site with a directory component lately and thought I would document the technique I am using to create this effect. It primarily uses Ditto and a snippet comprised of if else statements.

Document Structure

  1. Level One
    • The Directory will be contained within a folder, lets say it’s in the root of the site. I usually place a [!FirstChildRedirect!] snippet call in the content area of this document. This document is just a container.
  2. Level Two
    • The first child within this folder is used for a landing page. The content area describes the content/purpose of the directory. You can also create a dropdown navigational aid using another Ditto call (I will describe at the end of this article). This page is not a folder.
    • The rest of the child documents below this first one are all folders. These containers are used as categories within the directory. If the end user wants to add a new category all they have to do is create a new directory and it’s contents.
  3. Level Three
    • The children in this level are the individual items of the directory. These are individual documents, no more containers here.

Documents Structure and Fields

I place the Ditto calls within the template (actually within an if else snippet, see below). I then create all of my text fields as Template Variables. I also use ManagerManager snippet to hide any unused fields from the end user. That way all that is seen are the fields that are needed.

I chose the normal internal pages template for the landing page. That way the Ditto calls would not show up on this page. By using ManagerManger to hide the template selection field the user cannot change this template setting.

The Snippet(s)

I am assuming that you have some familiarity with the Ditto snippet used with MODx. What you may be realizing is that within this structure we are requiring two different Ditto calls. One if you are viewing a Level 2 directory and it’s child documents (Level 3). Another if you are directly viewing a Level 3 document.

To accomplish this I have created a snippet that is just a PHP if else statement (below) that uses the documentObject to determine if a directory is or is not present:

<?php
$Folder = $modx->documentObject['isfolder'];
if ($Folder=="1")
  $output="{{directoryFolder}}";
else
if ($Folder=="0")
 $output="{{directoryPages}}";
return "$output";
?>

Depending on whether or not the document is a folder a slightly different Ditto call within a chunk is called in.

This is the {{directoryFolder}} call:

[!Ditto? &startID=`[*id*]` &depth=`2` &tpl=`physicianTPL` &sortBy=`lastName` &sortDir=`asc` &summarize=`10` &paginate=`1` &paginateAlwaysShowLinks=`1`!]

and this is the {{directoryPages}} call:

[!Ditto? &documents=`[*id*]` &depth=`2` &tpl=`physicianTPL2` &summarize=`10` &paginate=`1` &paginateAlwaysShowLinks=`1`!]

Notice that I did use similiar, but slightly different TPLs here for layout. This was a personal choice, but I found that the Level2 and Level3 presentation of the same document required slightly different data presentation.

I do want to mention the TPL, placeholder structure here. It is possible to create a statement that calls in a field only when there is data present. In the example below I created a field to display a website link that display nothing if the field is left blank. All of the placeholders can be formatted in this way:

[+docLink:isnot=``:then=`<a href="[+docLink+]" title="[+pagetitle+]'s Website" target="_blank">[+pagetitle+]'s Website</a>`+]

The Dropdown Navigation

Once again I use Ditto to create another feature of the Directory. I created a chunk that uses a little JavaScript for a clickable dropdown menu:

<script language="JavaScript">
<!--
function goToNextPage()
{
PageIndex=document.form_menu.My_Choice.selectedIndex
if (document.form_menu.My_Choice.options[PageIndex].value != "none")
{
location = document.form_menu.My_Choice.options[PageIndex].value
}
}
-->
</script>
<form name="form_menu">
<select name="My_Choice" size="1" onchange="goToNextPage()">
<option value="none" selected="selected">WRHS Physicians</option>
[!Ditto? &startID=`6` &tpl=`dropdownTPL` &depth=`2` &sortBy=`lastName` &sortDir=`asc` &hideFolders=`1` &filter=`id,[*id*],2`!]
</select>
</form>

As you can see in my Ditto call I found it necessary to hide the categories (folders) and then used the filter to remove the landing page from the output.

The Wayfinder Navigation

As I put all of this together I have also used a Wayfinder call in to create a listing of all of the Level 2 directories in the sidebar of my site. Using this approach I am only displaying the categories (Level 2 folder) and not the category contents (Level 3 documents):

[!Wayfinder? &startId=`[[UltimateParent? &topLevel=`0`]]`&level=`1` &firstClass=`titleinteriornav`!]

By using all of the wonderful MODx tools at my disposal this approach has given me exactly the view(s) I need and allows an end user to create new categories without droping in any additional code or even changing templates (as I mentioned above, that field was hidden too). On their end I don’t know how this could be made any more straightforward for an end user.


ModxI am currently in the process of creating a physician directory for a larger health system site that is in redevelopment here at Pleth, LLC. As I was going through the motions of coding templates for my Ditto output I realized that with such a large number of fields per page my layout was beginning to suffer as fields were being left blank by the end user. I came across this PHx solution in the MODx forum and wanted to share it since it is a simple solution to an otherwise frustrating problem.

The basic structure I started with:

A Variable: [+avariable+]<br />

The new structure (uses backticks):

[+avariable:isnot=``:then='A Variable: [+avariable+]<br />`+]

ModxI have noticed from time to time that someone sends a tweet requesting MODx resource information. I can tell you that there are lots of folks doing really great work with MODx tutorials, like these at The Coding Pad.

While I personally haven’t yet written any MODx tutorials I thought it might be useful to identify some of the snippets/plugins that I use on a day to day basis. I am not looking to elaborate on some of the most commonly used snippets like Ditto or Wayfinder. I am hoping to illuminate some of those little golden bits of code that I find very useful if not a little hard to find.

CopyYears Snippet

This tiny little snippet comes in very handy. CopyYears simply updates the copyright year automatically. I realize that this may seem a little on the lazy side but when you manage dozens of MODx sites like we do here at Pleth it is very useful.

randomDoc Snippet

This is a simple and useful snippet that I have used in many instances. It randomly returns a single document within a directory. You should have all the standard MODx fields (and I believe Template Variables too) available to you. I was not able to track down the original source for the randomDoc snippet, so I am linking to my previous article on this topic (randomDoc Snippet).

sitemap Snippet

I realize that there are multiple methods for creating an XML sitemap on your MODx sites. My tried and true approach has been to use the Sitemap Snippet. Once again, it’s simplicity and ease of implementation make this an attractive solution for my sites.

getField Snippet

getField has quickly become one of my go-to snippets. It allows you to look up the document tree and retrieve fields from parent documents. In a previous post I outlined my method for piecing together code from multiple getField call ins.

documentMan Snippet

documentMan is a snippet I probably use the most widely. It allows you to quickly build lists based on the contents of any given directory. This can become a great timesaver as you do not have to hand code long lists like photogalleries. It also allows an end user to add to listings by simply uploading their document into the appropriate location and any accompanying code is written by the snippet. You can see an example of this in action in the Pleth Portfolio.

FeedX Snippet

FeedX, very handy:

FeedX is a universal XML feed reader for MODx. Rather than being limited to specific formats, the snippet is capable of parsing and rendering nearly any XML format (RSS, RDF, Atom, you name it). In addition to functioning as a snippet, FeedX’s class may be called by 3rd party snippets/plugins/modules as a simple method of retrieving cached and parsed XML data.

EZfaq Snippet

While EZfaq is very useful as intended I have found that with a little imagination it can be used to present all sorts of data. You can see it in action on the Pleth Policies and Procedures page.

ManagerManager Plugin

I elaborated on the ManagerManager Plugin in a recent post. Since writing that post I have continued to discover just how great this plugin is. If you are wanting to get into some serious MODx development you really need to learn the ins and outs of this powerful plugin.


This came by way of @spinkston, couldn’t be more true.


Until recently I have not looked too closely at the manager themes available for the MODx framework. I am getting started on a major redesign for one of our larger customers and this process began I decided to take a closer look at this side of MODx. What’s impressive is how readily these changes are made within the system.

MODx Carbon Manager Theme The theme that I quickly gravitated toward was the MODx Carbon Manager Theme by garborg. The graphics and color scheme are right on the money, I usually use the orange and white MODx theme that is one of the four default themes in the MODx install. It has always worked well for me, but this one is much easier on the eyes. With a few small tweaks I had it looking just the way I wanted.

I know that MODx Revolution 2.0-beta-1 was just released and has slick new administration side, but there are still a lot of us that will be using Evolution (0.9.6.3) for a little while longer yet. This should definitely be a helpful bit of code until the full release and that transition occurs.


I missed the last Refresh Central Arkansas meeting, but was able to catch it on the streaming Mogulus broadcast. I expect the video to be posted any time now on the Refresh Central Arkansas site. Thanks to Daniel Spillers and Kelly Griffin for a couple of informative presentations, these [...] Continue Reading…


As I was posting a solution in the MODx forums this morning I realized that I have never posted the use of the randomDoc snippet here. This is a simple and useful snippet that I have used in many instances. It randomly returns a single document within a directory. [...] Continue Reading…


I just came across a MODx forum post for a great new Twitter snippet by DaveChild. You can download the actual snippet code directly from the “Tweet This Snippet” forum post. So, thanks to DaveChild and Susan Ottwell for their contributions.

This snippet returns a link to twitter for the [...] Continue Reading…


For anyone who doesn’t know, Pleth’s data center is The Planet. Our servers are in Dallas and we backup everything to Houston. Over the years we have developed a bit of a love hate relationship with their customer support department. Over the last two days there have been some [...] Continue Reading…


I just wanted to pass along this handy file sharing service we use internally here at Pleth, LLC. ShareFile is a service we have used for the better part of 2 years now and continually recommend to our customers. We primarily use it to securely move large files between [...] Continue Reading…


Another member of the MODx community has come through with a freely available documentation tool to assist MODx developers. It is The Almost Complete Guide to Creating Menus in MODx using Wayfinder.

This is an escpecially significant piece of work since Wayfinder is one of the key snippets used [...] Continue Reading…


I just came across the MODx ManagerManager plugin and WOW! The flexibility of the MODx system and contributions of it’s community continues to impress me even now. One of my limitations with MODx, up till now, has been that I didn’t have a good method for specifically presenting selected [...] Continue Reading…


The Central Arkansas Refresh Group had another well attended meeting last night. The location was at a new venue, The Flying Saucer, in downtown Little Rock, Arkansas.

Our speakers were Refresh members Darren Huckey, @monstordh (who gave a brief overview of the CMS Platform Drupal) and Brant Collins, @brantc (who [...] Continue Reading…


It is 4:00pm on a Friday afternoon and I am just staring at my cup of Earl Grey. I would like to leave for the day, but I keep telling myself I need to write a blog post. At this juncture I am completely uninspired.

As I begin mindlessly [...] Continue Reading…


About 6 weeks ago I read the Ethan Marcotte article Fluid Grids and was notably impressed. For me, this was a technique that really changed things, got me thinking creatively on new ways to approach layout. So much so that I began going around the office telling everyone about [...] Continue Reading…