Skip to content

Conversation

@AndyButland
Copy link
Contributor

@AndyButland AndyButland commented Oct 16, 2025

Prerequisites

  • I have added steps to test this contribution in the description below

Fixes: #20524

Description

This was raised as a migration error, but it's not really - more a difference in how the 13 and 17 backoffice handles loading templates.

We have the concept of a "master template", i.e. a layout, which can be set via the UI when creating templates. If creating one at the root Layout = null; will be set. If creating under another template, something like Layout = "Layout.cshtml"; will.

The problem is that's not the only way to create a layout relationship with a template - you can just do it in the Razor code itself. So even if a template doesn't have a parent, it can still have something like Layout = "Layout.cshtml"; in the code.

Currently when a template loads, whether or not a parent exists is used to amend the code to set the layout to null or the master template as appropriate. So in the situation where a layout is set in code in a template at the root, Layout = null; will be written into the markup. When this happens you can see the file on disk is still correct with Layout = "Layout.cshtml";, and the template editor is dirty as you'll see a "Discard changes" message pop up if you try to navigate away.

This PR fixes this by not attempting to amend the Razor code on load - it'll now always keep whatever is on disk. Only when creating a template, or in setting a master template via the backoffice UI, will it continue to write the Layout setting in the template file.

Testing

  • Create two templates at the root.
  • Set one to be the layout of the other by changing Layout = null; to e.g. Layout = "MyLayout.cshtml"; in the .cshtml file.
  • Load the template in the backoffice.
  • Before this PR you'll see Layout = null; presented in the backoffice UI, whilst the file on disk is unchanged.
  • After this PR this change won't be made.
  • Verify that creating a template, at the root and under the parent, and using the backoffice UI picker interface to set and remove a master template, all correctly still modify the Razor code's Layout property.

Release

Merging this will include it for 17.0, but we could likely cherry-pick back to main for 16.4 too.

Copilot AI review requested due to automatic review settings October 16, 2025 13:19
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an issue where template layouts specified in Razor code were being overwritten when loading templates in the backoffice. The fix ensures that layout settings defined directly in template files are preserved rather than being automatically modified based on parent-child relationships.

  • Prevents automatic layout code modification when loading existing templates
  • Preserves user-defined layout settings in Razor template files
  • Maintains layout modification behavior for new template creation and UI-based changes

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
template-workspace.context.ts Added updateLayoutBlock parameter to setMasterTemplate method and modified load/create behavior to conditionally update layout blocks
template-workspace-editor.element.ts Updated calls to setMasterTemplate to explicitly enable layout block updates for UI-driven changes

@iOvergaard iOvergaard merged commit 65798b5 into release/17.0 Oct 17, 2025
24 checks passed
@iOvergaard iOvergaard deleted the v16/bugfix/retain-layout-from-file-when-loading-template branch October 17, 2025 08:46
iOvergaard pushed a commit that referenced this pull request Oct 17, 2025
…) (#20529)

Retain layout from file when loading template.
@iOvergaard
Copy link
Contributor

Picked to main with a3a8be4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants