Where have all the children gone? Hacking wayfinder in Mod-x

One of the reasons I set up this blog was to post up those dusty rarities – pieces of code I’ve created that might be of use to others.

Working on a site in the excellent open source CMS MODx I needed to create a site map. The site featured a mix of static and dynamic pages, the latter featuring things that would drop in and out of the site with time so I needed a snippet to filter the documents in the site accordingly when creating the site map.

Handily, MODx has just one such snippet built into its core called Wayfinder which is designed for the express purpose of creating lists of documents within the document tree. However, one shortcoming of Wayfinder is that it is a pain to ignore children documents when generating a list from the document tree without also ignoring their parent. In Plain English, if I have a news folder which contains individual news items and I want in my site map to include the news folder/parent but not its childrens (the individual news items) it is difficult to achieve this without

  1. specifying all the children you want to ignore in the wayfinder call that generates the list (not desirable for the technically unitiated ie content populators/managers), or
  1. deselecting an option for each child file that is added during content population (a bit of a hassle)

So, one simple tricky solution was to hack into the Wayfinder snippet, adding the ignoreKids parameter to achieve just this.
Now, when calling wayfinder from within MODx just add &ignoreKids=`X` as a parameter with X being a comma-separated list of document ids for those document parents/containers that you want to appear in the wayfinder list but not their children, eg:

[!Wayfinder? &startId=`0` &level=`3` &ignoreKids=`75,77,78`!]

This will perform the Wayfinder snippet, including documents 75, 77 and 78 but ignoring any of their child documents.

Instructions

Download wayfinder.ignoreKids.hack.zip

This zip file contains two php files: wayfinder.inc.php and wayfinder.snippet.php. Replace the snippet call in MODx with wayfinder.snippet.php and replace the wayfinder.inc.php file that is in your /assets/snippets/wayfinder folder.

Comments

to be used in conjunction with {{daddyIssues}} yea? good seeing you guys today, hope you’re all dry now :)