{"record":{"id":"f9008bbfbed2ff00","repo":"octobercms/october","slug":"unable-to-find-a-registered-layout-with-code","errorCode":null,"errorMessage":"Unable to find a registered layout with code: ","messagePattern":"Unable to find a registered layout with code: ","errorType":"exception","errorClass":"ApplicationException","httpStatus":null,"severity":"error","filePath":"modules/system/models/MailLayout.php","lineNumber":139,"sourceCode":"            $layout->save();\n        }\n\n        self::$codeCache = null;\n    }\n\n    /**\n     * fillFromCode\n     */\n    public function fillFromCode($code = null)\n    {\n        $definitions = MailManager::instance()->listRegisteredLayouts();\n\n        if ($code === null) {\n            $code = $this->code;\n        }\n\n        if (!$definition = array_get($definitions, $code)) {\n            throw new ApplicationException('Unable to find a registered layout with code: '.$code);\n        }\n\n        $this->fillFromView($definition);\n    }\n\n    /**\n     * fillFromView\n     */\n    public function fillFromView($path)\n    {\n        $sections = self::getTemplateSections($path);\n\n        $defaultCss = '\n@media only screen and (max-width: 600px) {\n    .inner-body {\n        width: 100% !important;\n    }\n","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/octobercms/october/blob/b608633a7e8922487d91a8161499020121c3b3bf/modules/system/models/MailLayout.php#L121-L157","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Restore the registration: add the code back to the providing plugin's registerMailLayouts()","Or remove the orphaned row via the backend mail layout list / database","If the plugin was disabled intentionally, delete its leftover mail layout rows so sync no longer touches them"],"exampleFix":"// before: a layout row has code 'acme.invoice' but nothing registers it\n\n// after, in the plugin's Plugin.php\npublic function registerMailLayouts()\n{\n    return [\n        'acme.invoice' => 'acme.plugin::mail.layouts.invoice',\n    ];\n}","handlingStrategy":"validation","validationCode":"$registered = \\System\\Classes\\MailManager::instance()->listRegisteredLayouts();\nif (!array_key_exists($code, $registered)) {\n    // skip fillFromCode; the code has no registered view source\n}","typeGuard":null,"tryCatchPattern":"try { $layout->fillFromCode($code); } catch (\\ApplicationException $ex) { /* the plugin providing this layout is missing; remove the orphaned row or re-register it */ }","preventionTips":["Keep registerMailLayouts() codes stable across plugin versions","When uninstalling a plugin, delete its seeded mail layout rows","Before syncing mail templates, verify each row's code exists in listRegisteredLayouts()"],"tags":["mail","layout","registration","not-found"],"backgroundTag":"resource-not-found","analyzedSha":"b608633a7e8922487d91a8161499020121c3b3bf","analyzedAt":"2026-08-21T04:24:57.515Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}