{"record":{"id":"507c9d7d081c1b24","repo":"octobercms/october","slug":"the-template-cannot-be-updated","errorCode":null,"errorMessage":"The template cannot be updated.","messagePattern":"The template cannot be updated\\.","errorType":"exception","errorClass":"ApplicationException","httpStatus":null,"severity":"error","filePath":"modules/cms/classes/editorextension/HasExtensionCrud.php","lineNumber":359,"sourceCode":"\n        if (!$template instanceof HalcyonModel) {\n            return false;\n        }\n\n        if (!$this->getTheme()->secondLayerEnabled()) {\n            return false;\n        }\n\n        return $this->getThemeDatasource()->hasModelAtIndex(1, $template);\n    }\n\n    /**\n     * updateTemplateFile\n     */\n    protected function updateTemplateFile($template, $documentType, $templatePath)\n    {\n        if (!$this->canUpdateTemplateFile($template)) {\n            throw new ApplicationException('The template cannot be updated.');\n        }\n\n        // Update second layer, then delete first layer\n        $datasource = $this->getThemeDatasource();\n        $datasource->updateModelAtIndex(1, $template);\n        $datasource->forceDeleteModelAtIndex(0, $template);\n\n        $template = $this->loadTemplate($documentType, $templatePath);\n        return [\n            'metadata' => $this->loadTemplateMetadata($template, ['type'=>$documentType]),\n            'templateFileUpdated' => true\n        ];\n    }\n\n    /**\n     * canResetFromTemplateFile returns true if the database template can be reloaded from the\n     * template file. Only available when the database templates are enabled, and the template\n     * exists in both the database and filesystem.","sourceCodeStart":341,"sourceCodeEnd":377,"githubUrl":"https://github.com/octobercms/october/blob/b608633a7e8922487d91a8161499020121c3b3bf/modules/cms/classes/editorextension/HasExtensionCrud.php#L341-L377","documentation":"updateTemplateFile() (the editor's 'save template back to the filesystem' action) is only allowed when canUpdateTemplateFile() passes: app.debug must be true, the template must be a Halcyon model, the theme must have its second layer (database templates) enabled, and the template must exist in the filesystem datasource layer. Otherwise it throws 'The template cannot be updated.'","triggerScenarios":"Invoking the updateTemplateFile editor action with APP_DEBUG disabled (typical production), when the theme's second layer / database templates are not enabled, or when the template has no filesystem copy (database-only template).","commonSituations":"Trying to push database-layer template content back to files on production where debug is off; themes not configured with two datasources; templates created purely in the database layer.","solutions":["Enable debug mode locally (APP_DEBUG=true) and retry — the action is deliberately restricted to development","Enable the theme's second-layer/database-template configuration so both datasource layers exist","Ensure the template has a filesystem copy (it must be present in the filesystem datasource layer); export it to the theme directory first","If you only want to revert DB changes, use 'reset from file' (requires both layers) or copy the content manually"],"exampleFix":"# before (.env, production)\nAPP_DEBUG=false\n\n# after (local dev only, while updating template files)\nAPP_DEBUG=true","handlingStrategy":"validation","validationCode":"$canUpdate = Config::get('app.debug', false)\n    && $template instanceof \\October\\Rain\\Halcyon\\Model\n    && $theme->secondLayerEnabled()\n    && $theme->getDatasource()->hasModelAtIndex(1, $template);\nif (!$canUpdate) {\n    // hide the 'update template file' action instead of letting the server throw\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Gate the 'update template file' UI action on the same conditions the server checks (debug + second layer + file exists)","Keep this action out of production by leaving APP_DEBUG=false there","Verify second-layer (database templates) configuration before offering file-write flows"],"tags":["editor","template","debug-mode","database-templates","cms"],"backgroundTag":"operation-not-permitted","analyzedSha":"b608633a7e8922487d91a8161499020121c3b3bf","analyzedAt":"2026-08-21T04:24:57.515Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}