Over the last few years I have gotten more and more proficient with building complex, MODx Wayfinder calls to meet my development needs. I have found that if I spend a little extra time constructing my snippet calls I can create single calls that serve my purposes in multiple situations. While this is a satisfying process, once completed, it can be very frustrating to create and test these calls while taking up a lot of valuable time. It finally occurred to me recently that I could take an alternative approach.
Rather than trying to build one-size-fits-all Wayfinder calls, why not build a snippet that allows me to choose from very simple and specific calls dependent on criteria like template ID, document depth (Aaron Ladage’s Count Snippet) and whether the document is a folder or not. These are just examples that I used in my last site development. I imagine that you could use any available MODx variables for your snippet logic.
<?php $TempId = $modx->documentObject['template']; $CountLocation = $modx->runSnippet('Count'); $Folder = $modx->documentObject['isfolder']; if ($TempId=="1" && $CountLocation=="0" && $Folder=="1") { $output="{{template1depth0folder1}}"; } else if ($TempId=="1" && $CountLocation=="0" && $Folder=="0") { $output="{{template1depth0folder0}}"; } else if ($TempId=="1" && $CountLocation=="1" && $Folder=="0") { $output="{{template1depth1folder0}}"; }else if ($TempId=="1" && $CountLocation=="2" && $Folder=="0") { $output="{{template1depth2folder0}}"; } else if ($TempId=="2") { $output="{{template2}}"; } else { $output="{{defaultNavigation}}"; } return "$output"; ?>



