Jump to main content Jump to doc navigation

Creating MODX custom manager pages (CMPs) needs three things: a Namespace path, a menu item, and PHP files.

Setting the Namespace Path

Create a Namespace (Admin > Namespaces) called “mycmp”. Set its path to “{core_path}components/mycmp/” and its Assets Path to “{assets_path}components/mycmp/”.

To avoid problems, keep the namespace and the action lowercase, with alphanumeric characters only (no spaces, hyphens, or underscores). The namespace should be a lowercase version of the CMP name.

Creating the Menu

Go to Admin -> Menus and create a menu item under “Extras”:

Set the Namespace to “mycmp” and the Action to “welcome”. The manager loads the “welcome” controller by default.

Creating the Controller File

Create the controller at {core\_path}components/mycmp/controllers/default/welcome.class.php:

  • controllers/ — where MODX looks for controllers.
  • default/ — the current Manager Theme, so you can ship different controllers per theme.
  • welcome.class.php — named after the “welcome” action from the menu. An action of “home” would mean home.class.php.

File contents:

<?php
class MycmpWelcomeManagerController extends modExtraManagerController {
    public function process(array $scriptProperties = array()) {}
    public function getPageTitle() {
        return 'My Test CMP';
    }
    public function getTemplateFile() {
        return 'welcome.tpl';
    }
}

The class name starts with the CMP name (lowercase namespace) plus the action, followed by ManagerController. process() stays empty here — there is no business logic. getPageTitle() sets the page title; getTemplateFile() points MODX at the template.

Creating the Template File

CMP pages use Smarty templates. MODX looks in [namespace-path]templates/; the controller only names the file (subdirectories allowed). Create {core\_path}components/mycmp/templates/default/welcome.tpl:

<div class="container">
<h2>Welcome!</h2>
</div>

The template adds padding around an h2. The manager displays:

The CMP is now reachable at /url/to/modx/manager/?a=welcome&namespace=mycmp — simpler than the ID-based actions of 2.2 and earlier. (The manager reads the controller name from the a parameter; action is the equivalent parameter used by connectors, not the manager.)

modExtraManagerController has more API methods to override. In the CMP itself you can use MODExt and related tools — beyond the scope of this tutorial.

Support the team building MODX with a monthly donation.

The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.

Backers

  • modmore
  • STERC
  • Digital Penguin
  • Jens Wittmann – Gestaltung & Entwicklung
  • CrewMark
  • Fabian Christen
  • Sepia River Studios
  • Dannevang Digital
  • Alex
  • A. Moreno
  • Chris Fickling
  • Stéphane Jäggi
  • Murray Wood
  • Anton Tarasov
  • JT Skaggs
  • deJaya
  • Lefthandmedia
  • eydolan
  • Following Sea
  • Guido Gallenkamp
  • YJ
  • Raffy
  • Snow Creative
  • Nick Clark
  • Guest
  • Helen
  • krisznet
  • Yanni
  • Richard

Budget

$194 per month—let's make that $500!

Learn more