octobercms/october · error · ApplicationException

Unable to find a registered layout with code:

Error message

Unable to find a registered layout with code: 

What it means

MailLayout::fillFromCode($code) resolves layout definitions registered with MailManager (plugins declare them via registerMailLayouts(), mapping code => view path). When the model's code is absent from listRegisteredLayouts(), it throws 'Unable to find a registered layout with code: <code>' because there is no source view to fillFromView() from.

Source

Thrown at modules/system/models/MailLayout.php:139

            $layout->save();
        }

        self::$codeCache = null;
    }

    /**
     * fillFromCode
     */
    public function fillFromCode($code = null)
    {
        $definitions = MailManager::instance()->listRegisteredLayouts();

        if ($code === null) {
            $code = $this->code;
        }

        if (!$definition = array_get($definitions, $code)) {
            throw new ApplicationException('Unable to find a registered layout with code: '.$code);
        }

        $this->fillFromView($definition);
    }

    /**
     * fillFromView
     */
    public function fillFromView($path)
    {
        $sections = self::getTemplateSections($path);

        $defaultCss = '
@media only screen and (max-width: 600px) {
    .inner-body {
        width: 100% !important;
    }

View on GitHub (pinned to b608633a7e)

Solutions

  1. Restore the registration: add the code back to the providing plugin's registerMailLayouts()
  2. Or remove the orphaned row via the backend mail layout list / database
  3. If the plugin was disabled intentionally, delete its leftover mail layout rows so sync no longer touches them

Example fix

// before: a layout row has code 'acme.invoice' but nothing registers it

// after, in the plugin's Plugin.php
public function registerMailLayouts()
{
    return [
        'acme.invoice' => 'acme.plugin::mail.layouts.invoice',
    ];
}
Defensive patterns

Strategy: validation

Validate before calling

$registered = \System\Classes\MailManager::instance()->listRegisteredLayouts();
if (!array_key_exists($code, $registered)) {
    // skip fillFromCode; the code has no registered view source
}

Try / catch

try { $layout->fillFromCode($code); } catch (\ApplicationException $ex) { /* the plugin providing this layout is missing; remove the orphaned row or re-register it */ }

Prevention

When it happens

Trigger: A mail_layouts row whose code no plugin registers: the providing plugin was uninstalled or disabled while its seeded row remained; the code was edited in the DB or mis-typed when seeding; registering plugin failed to boot.

Common situations: Uninstalling a plugin that registered mail layouts but leaving orphaned rows; syncing mail templates after a plugin rename; editing the code field in the backend mail UI.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of octobercms/october@b608633a7e (2026-08-21). Data as JSON: /api/errors/f9008bbfbed2ff00. Report an issue: GitHub.