Jump to main content Jump to doc navigation

Event: OnDocPublished

Called when a Resource is published via the Publish context menu.

  • Service: 5 - Template Service Events
  • Group: None

Event Parameters

Name Description
docid The ID of the resource being published. (deprecated)
id The ID of the resource being published.
resource A reference to the modResource object being published.

Important! Before using this event, you need to know

The event fires only when a resource is published via the document context menu in the resource tree. If you check the published checkbox while editing a document on the page of the document itself, nothing happens.


Such a plugin will display an array of the published resource in the "Error log", and a success message on the screen:

$eventName = $modx->event->name;
switch($eventName) {
    case 'OnDocPublished':
        $response = array(
        	'success' => false,
        	'message' => 'The publication was successful!',
        	'data' => array(),
        echo $modx->toJSON($response);
        $modx->log(modX::LOG_LEVEL_ERROR, print_r($resource->toArray(),true));

See Also

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.


  • modmore
  • modmore
  • Jens Wittmann – Gestaltung & Entwicklung
  • Raffy
  • eydolan
  • Digital Penguin
  • Fabian Christen
  • Dannevang Digital
  • deJaya
  • Sepia River Studios
  • Following Sea
  • Anton Tarasov
  • Lefthandmedia
  • Nick Clark
  • Chris Fickling
  • Murray Wood
  • YJ
  • CrewMark
  • Richard


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

Learn more