Did you ever wish you could use some of MODX’s capabilities in a script running outside of MODX? Sometimes, it’s nice to be able to use
$modx->getChunk() to get some content or
$modx->runSnippet() to use a utility snippet. It’s also handy to be able to get and manipulate various MODX objects like Resources, Users, Templates, Chunks, and TVs in a script without having to create a snippet inside MODX to do it.
I end up writing a fair number of extras and utility scripts that can run both inside and outside MODX, so I’ve had to develop a fairly reliable method for instantiating the
$modx object in a way that keeps things from falling apart. When I need MODX outside of MODX, I use some variation of the following code. You can put the code directly in your PHP file or use
include to pull it in. Learn More