octobercms/october · error · ApplicationException
The template cannot be updated.
Error message
The template cannot be updated.
What it means
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.'
Source
Thrown at modules/cms/classes/editorextension/HasExtensionCrud.php:359
if (!$template instanceof HalcyonModel) {
return false;
}
if (!$this->getTheme()->secondLayerEnabled()) {
return false;
}
return $this->getThemeDatasource()->hasModelAtIndex(1, $template);
}
/**
* updateTemplateFile
*/
protected function updateTemplateFile($template, $documentType, $templatePath)
{
if (!$this->canUpdateTemplateFile($template)) {
throw new ApplicationException('The template cannot be updated.');
}
// Update second layer, then delete first layer
$datasource = $this->getThemeDatasource();
$datasource->updateModelAtIndex(1, $template);
$datasource->forceDeleteModelAtIndex(0, $template);
$template = $this->loadTemplate($documentType, $templatePath);
return [
'metadata' => $this->loadTemplateMetadata($template, ['type'=>$documentType]),
'templateFileUpdated' => true
];
}
/**
* canResetFromTemplateFile returns true if the database template can be reloaded from the
* template file. Only available when the database templates are enabled, and the template
* exists in both the database and filesystem.View on GitHub (pinned to b608633a7e)
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
Example fix
# before (.env, production) APP_DEBUG=false # after (local dev only, while updating template files) APP_DEBUG=true
Defensive patterns
Strategy: validation
Validate before calling
$canUpdate = Config::get('app.debug', false)
&& $template instanceof \October\Rain\Halcyon\Model
&& $theme->secondLayerEnabled()
&& $theme->getDatasource()->hasModelAtIndex(1, $template);
if (!$canUpdate) {
// hide the 'update template file' action instead of letting the server throw
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- Cannot reset template from file.
- cms::lang.template.not_found
- cms::lang.partial.not_found_name
- cms::lang.content.not_found_name
- Component not found
AI-assisted analysis of octobercms/october@b608633a7e (2026-08-21).
Data as JSON: /api/errors/507c9d7d081c1b24.
Report an issue: GitHub.