{"record":{"id":"745f9386754dc517","repo":"octobercms/october","slug":"cannot-reset-template-from-file","errorCode":null,"errorMessage":"Cannot reset template from file.","messagePattern":"Cannot reset template from file\\.","errorType":"exception","errorClass":"ApplicationException","httpStatus":null,"severity":"error","filePath":"modules/cms/classes/editorextension/HasExtensionCrud.php","lineNumber":401,"sourceCode":"        }\n\n        if (!$this->getTheme()->secondLayerEnabled()) {\n            return false;\n        }\n\n        $datasource = $this->getThemeDatasource();\n        return $datasource->hasModelAtIndex(0, $template) &&\n            $datasource->hasModelAtIndex(1, $template);\n    }\n\n    /**\n     * resetFromTemplateFile\n     */\n    protected function resetFromTemplateFile($documentType, $templatePath)\n    {\n        $template = $this->loadTemplate($documentType, $templatePath);\n        if (!$this->canResetFromTemplateFile($template)) {\n            throw new ApplicationException('Cannot reset template from file.');\n        }\n\n        // Delete first layer\n        $datasource = $this->getThemeDatasource();\n        $datasource->forceDeleteModelAtIndex(0, $template);\n    }\n\n    /**\n     * getThemeDatasource returns a theme datasource object\n     */\n    protected function getThemeDatasource()\n    {\n        return $this->getTheme()->getDatasource();\n    }\n\n    /**\n     * getRequestMetadata\n     */","sourceCodeStart":383,"sourceCodeEnd":419,"githubUrl":"https://github.com/octobercms/october/blob/b608633a7e8922487d91a8161499020121c3b3bf/modules/cms/classes/editorextension/HasExtensionCrud.php#L383-L419","documentation":"resetFromTemplateFile() discards the database (first-layer) copy of a template so the filesystem version takes effect again. It requires canResetFromTemplateFile(): the template must be a Halcyon model, the theme's second layer (database templates) must be enabled, and the template must exist in BOTH datasource layers; otherwise it throws 'Cannot reset template from file.'","triggerScenarios":"The editor's 'reset from file' action on a template that exists in only one layer — database-only (created in the editor, never written to disk) or file-only (file deleted/never copied) — or on a theme whose second layer is disabled.","commonSituations":"Templates created via the editor's database layer with no file counterpart; theme files removed from disk; theme datasource config missing the second layer; environments where database templates were switched off.","solutions":["Ensure the template exists in both layers: a file under themes/<theme>/<typeDir>/ AND a database copy","Verify the theme's second layer (database templates) is enabled","If the file is missing, recreate it, or use 'update template file' (debug mode required) to write database content to disk first"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"$ds = $theme->getDatasource();\n$canReset = $template instanceof \\October\\Rain\\Halcyon\\Model\n    && $theme->secondLayerEnabled()\n    && $ds->hasModelAtIndex(0, $template)\n    && $ds->hasModelAtIndex(1, $template);\nif (!$canReset) {\n    // hide or disable 'reset from file' rather than calling it\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only show 'reset from file' when both datasource layers contain the template","Write templates to both layers before advertising reset actions","Monitor theme datasource configuration changes when enabling/disabling database templates"],"tags":["editor","template","database-templates","cms","datasource"],"backgroundTag":"operation-not-permitted","analyzedSha":"b608633a7e8922487d91a8161499020121c3b3bf","analyzedAt":"2026-08-21T04:24:57.515Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}