
MODx Manager Interface
Okay, so the title may be a bit overstated. There are a number of very good Content Management Systems, and sometimes, it just comes down to personal preference. However, MODx has the power and potential to make it to the top of just about anyone’s favorites list.
What is MODx?
It’s a Content Management System (CMS). A CMS at its heart is simply a nice GUI backend for managing your site’s template and content. What makes one CMS better than another is its additional built-in features and/or extensibility. That latter is where MODx outshines all the others.
As far as built-in features go, MODx falls more on the simplistic side, but its simplicity is what makes it so great. It has all the things you would expect from a good CMS. User management, templating, content editing, document management, etc. What it doesn’t have is a lot of hard coded features you may never use and mostly just get in the way. MODx achieves this with insane extensibility, allowing you to add custom dynamic features to any part of your site or even MODx itself.
You can make MODx anything you want it to be: a simple website, ecommerce store, blog, whatever. Some other CMS solutions provide so many built-in features that it either ends up taking great effort getting it just the way you want or your site ends up cookie-cutter.
How does MODx work?
Everything you put in MODx falls into one of the following categories: template, chunk, template variable, snippet, plugin, module, or document. Let’s see what each is and how they add up to make one of the most powerful CMS solutions around.
Templates
Just as you would imagine, these hold the actual HTML code that makes up your site’s layout and structure. You can create as many as you need or want, and they can be switched out on a document by document basis. This allows you to easily create home page and sub page layouts or even entirely custom layouts just for specific portions of your site. Templates are stored in the database and don’t mix and match HTML and PHP like many CMS templates do. This doesn’t make them less customizable, though, as MODx utitlizes a parser and template tags to allow you to pull in content or dynamic code. This makes it very easy for inexperienced designers to create sites.
Chunks
Chunks are simply pieces of HTML or content, intended to be dropped-in to portions of your site. The best principle every conceived in my opinion is DRY: Don’t Repeat Yourself, and chunks give you the power to accomplish that. Anything on your site that might be used again anywhere else goes into a chunk. Then it’s simply a matter of “calling” it somewhere within your template or even another chunk, using the format: {{chunkName}}. Then, MODx will find any occurrence of this an replace it with the actual content stored in that chunk.
Template Variables
On their surface, template variables are simple things. You create a template variable and specify what type of form field it should be: textbox, textarea, dropdown, etc. Then, you tie it to one or more templates, and any documents that make use of those templates will have fields for you to specify the template variable’s value. That value can then be called anywhere on your site, much like a chunk but with a slightly different format: [*templateVariableName*]. You could almost think of template variables as chunks that you can specify on a page-by-page basis. A common use case is adding “head” and “foot” template variables which get placed before the closing </head> tag and before the closing </body> tag, respectively. With that in place you can then add additional things to the HTML meta or extra stylesheets or javascript only for specific pages.
If that’s all template variables could do, it would make them extremely powerful, but they have more tricks up their sleeve. Template variables can be used to pull data from the database, evaluate one-off PHP scripts, and many other rather complex tasks. They could be a post in themselves and might end up that way if I get properly motivated. For now, though, the main thing to take away is that if MODx could do nothing else but work with template variables, it would still be a powerhouse of a CMS. They are just that good.
Snippets
Snippets are custom PHP scripts that can do anything, limited only by PHP itself and your imagination. However, they could be better thought of as functions, since MODx expects them to return something; though, it’s not required that they do. Snippets are “called” like chunks or template variables with a few exceptions. The general format for calling a snippet is [[snippetName]]. That form will result in a “cached call”. MODx will cache what the snippet returned and use it again rather than rerun the snippet code. This can create great performance improvements for content that needs to be dynamically fetched or manipulated in some way, but remains basically static afterwards. To do an “uncached call”, the format is: [!snippetName!]. (Notice the excalamation points.) Everytime MODx parses this type of snippet call, it will rerun the snippet code for a new result.
Since snippets are essentially functions, it follows that you would often need to pass in values. Thankfully there’s a rather simplistic way to do so: [[snippetName? ¶meter=`someValue`]]. Instead of closing the call after the snippet name, we now put in a question mark. (For me, it helps to look at this almost like a GET request in a URL, as they are very similar.) Then, you can specify as many parameters as you would like or need. The parameter’s value is wrapped by backticks (the key that’s typically on the far left of your keyboard just above the Tab key). This allows you to use single and double quotes in the parameter’s value without having to worry about escaping them with a forward slash. MODx will create PHP variables out of these parameters for you (much like PHP Globals would do with request variables), so any parameter you pass into the snippet will be instantly available to your snippet as $parameter.
Plugins
Plugins provide low-level access into the MODx system. MODx comes with a number of system events builtin. (The potential to add more of your own is there, but is way too complicated for the average user, though a future version promises to make it simpler. Regardless, the builtin system events cover most use cases.) The plugin itself is just PHP and just like snippets, is limited only by PHP itself and your own imagination. The main difference is that snippets are run independently during the document parsing stage, whereas plugins can tie into one or more stages of MODx’s page rendering and add to or alter portions of the page. This is extremely powerful and much simpler to set up than any other CMS’s plugin system.
Modules
Modules actually allow you to add to the MODx interface. They are composed of one or more snippets or plugins. The module code itself specifies the UI that should be set up for working with your addition. MODx comes with the DocManager module by default, which lets you change document permissions, templates, etc. to many documents at once. One of my favorite MODx modules (not pre-installed) is the DocFinder module which namely adds search and replace functionality across your entire site’s content. It’s an absolute thing of beauty.
Documents
Finally, documents are the actual pages that make up your site. They can be HTML or you can choose from other mime types such as XML, RSS, plain text, etc. You can make pages “containers” and then add sub pages into that container to set up you site structure. You can publish and unpublish pages on the fly. They become even more powerful when you have multiple site editors, as you can set up group or single-user access to documents on the fly. This also makes MODx a rather good CMS for clients, as you can allow your clients to make changes to specific portions of the site while blocking access to specific documents and site templates.
Where can I get MODx?
This was a very high-level overview of what MODx is and what it can do. I plan to go deeper into more of the internals in future posts. For the time being, though, your appetite should be sufficiently wetted enough to give MODx a try. You can get MODx from their downloads area. They also have a rather extensive repository of snippets, plugins, and modules you might want to check out. There’s also a live MODx demo now up at OpenCMS, if you want to play with it before you give it an install.