PHP Joomla! 6 Joomla! 5 Module Intermediate

Create a Modern Module Dispatcher Extending AbstractModuleDispatcher

Implements getLayoutData() with HelperFactoryAwareTrait to inject clean data into module tmpl layouts.

Updated on 24 November 2026 52 copies 175 views
modules/mod_example/src/Dispatcher/Dispatcher.php
<?php

declare(strict_types=1);

namespace Vendor\Module\Example\Site\Dispatcher;

\defined('_JEXEC') or die;

use Joomla\CMS\Dispatcher\AbstractModuleDispatcher;
use Joomla\CMS\Helper\HelperFactoryAwareInterface;
use Joomla\CMS\Helper\HelperFactoryAwareTrait;

class Dispatcher extends AbstractModuleDispatcher implements HelperFactoryAwareInterface
{
    use HelperFactoryAwareTrait;

    protected function getLayoutData(): array
    {
        $data = parent::getLayoutData();

        $helper        = $this->getHelperFactory()->getHelper('ExampleHelper');
        $data['items'] = $helper->getItems($data['params'], $this->getApplication());

        return $data;
    }
}
Every key returned by getLayoutData() becomes a local variable inside tmpl/*.php.

Technical explanation and best practices

A module Dispatcher replaces loose procedural code from legacy entry files. It resolves helper services via HelperFactoryAwareTrait and passes typed arrays directly into the active layout template.

Direct Engineering

Have a Joomla project or technical challenge in mind?

From architectural diagnosis to production deployment, directly with the engineer.