This post will reference a couple of my earlier posts:Modx

  1. Using TVs Above and Below Content
  2. Ditto/PHx Directory w/Cross-Categorization

The Snippet and Typical Usage

One of my more interesting finds of late is the Include Snippet. What this does is allow you to place your snippets in external files and then execute them from within MODx. What this snippet is typically being utilized for is to place snippets externally to achieve performance benefits secondary to sidestepping limitations in Evo’s caching mechanism. I am not examining this use or any performance benefits in this post.

The Issue

In my post, Ditto/PHx Directory w/Cross-Categorization, I outlined how you can create a site Personnel Directory. Once populated with personnel data this approach allows you to use Ditto to call in groups of people by Category. We have found that if we create a secondary organizational Template Variable (TV) using multi-select dropdowns, we were able to construct another organizational layer that existed in addition to the actual categories. This secondary organizational structure allowed us to thread together groups of people across the greater primary categories. We then created Ditto calls and utilized it’s filtering to organize/reorganize groups of personnel on the fly.

While this resulted in a very versatile approach to display personnel data across the site it did have unintended drawbacks. As I outlined in Using TVs Above and Below Content, we began placing Ditto calls in the [*belowContent*] TVs to display personnel data that was relevant to that particular page topic. As development progressed I realized the number of our Ditto calls was increasing, there was no good method for finding where the Ditto calls were located and it was becoming difficult to maintain a consistent approach across all instances of the snippet calls.

The Solution

The solution to this issue was to bring in the Includes snippet and place all of my Ditto calls, for this usage, into a single document. Now, each instance of my Ditto calls would be replaced with:

[!Include? &file=`assets/includes/dittocalls.php`!]

Now, in my dittocalls.php document I needed to differentiate which Ditto call I wanted to have expressed. Since this was essentially tied to a specific MODx document I used serial PHX statements similar to these:

[+phx:if=`[*id*]`:is=`388`:then=`<h3>Staff</h3>
[[Ditto?  &startID=`59` &depth=`2` &tpl=`individualTPL2` &hideFolders=`1` &sortBy=`menuindex` &sortDir=`asc` &noResults=`{{empty}}`]]
`:else=``+]
[+phx:if=`[*id*]`:is=`408`:then=`<h3>For More Information</h3>
[[Ditto?  &startID=`30` &depth=`2` &filter=`miscellaneous,CareerDevelopment,7` &tpl=`individualTPL2` &hideFolders=`1` &sortBy=`menuindex` &sortDir=`asc` &noResults=`{{empty}}`]]
`:else=``+]

Using this approach I was able to push all of these calls into a single document. This allowed me to easily find which Ditto calls I was utilizing, where they were being expressed and how each Ditto statement was being structured in relation to each of the other statements across the site.

I do realize that I could have placed a single Includes Snippet directly into my template. That may have been the better way to go about this rather than multiple instances of the same call, but I was unsure about the impact of this technique on my site performance. After all, this was only going to be utilized on a comparative handful of pages given the overall size of my site. I would love to hear any feedback on that point.

  • Romain

    Interresting article Greg.
    Eventhough the more i ear it's a good practice to externalize files (like snippets and chunks) for performance, the more i'd like to see some bench to see the benefices.

  • http://www.cheap-nikeshox.com/nike-shox-R5-women.html shox oz men

    Well , the view of the passage is totally correct ,your details is really reasonable and spring-bags.com you guy give us valuable informative post, I totally agree the standpoint of upstairs. I often surfing on this forum when I m free and I find there are so much good information we can learn in this forum!