Build MODX Menus with rootResource

rootResource is an alternative to the popular "UltimateParent" MODX Snippet

Nov 17, 2014

If you've used MODX before, you may be familiar with the  UltimateParent Snippet, used to get the Resource ID of the highest-level parent of a given child Resource. However, I'm often adding "toPlaceholder" support to it, and almost never utilize the "top" and "topLevel" features (nor can I ever remember exactly what they do LOL)

Anyways, here's a quick little alternative that doesn't have any loops, always grabs the ID of the "Root Resource" (aka "Ultimate Parent"), and has "toPlaceholder" support built-in. It's just a gist called rootResource:

Use Cases?

  • If you're calling UltimateParent multiple times in your Template/Chunk, consider using rootResource with the placeholder feature.
  • If you don't need the "top" and "topLevel" features, rootResource may be easier to grok, with tiny, theoretical, performance benefits.