diff --git a/src/Umbraco.Web.UI.Client/src/packages/templating/templates/repository/detail/template-detail.server.data-source.ts b/src/Umbraco.Web.UI.Client/src/packages/templating/templates/repository/detail/template-detail.server.data-source.ts index c6920483d7..f0fe1ab340 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/templating/templates/repository/detail/template-detail.server.data-source.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/templating/templates/repository/detail/template-detail.server.data-source.ts @@ -43,7 +43,7 @@ export class UmbTemplateServerDataSource implements UmbDetailDataSource @@ -72,13 +73,15 @@ export class UmbTemplateWorkspaceContext return response; } - async create(parent: any) { - const data = await this.createScaffold({ parent }); + async create(parent: UmbEntityModel) { + const data = await this.createScaffold({ + parent, + }); + + // Set or reset the master template + // This is important to reset when a new template is created so the UI reflects the correct state + await this.setMasterTemplate(parent.unique); - if (data) { - if (!parent) return; - await this.setMasterTemplate(parent.unique); - } return data; } @@ -98,20 +101,21 @@ export class UmbTemplateWorkspaceContext return this.getData()?.content ? this.getLayoutBlockRegexPattern().test(this.getData()?.content as string) : false; } - async setMasterTemplate(id: string | null) { - if (id === null) { + async setMasterTemplate(unique: string | null) { + if (unique === null) { this.#masterTemplate.setValue(null); - this.#updateMasterTemplateLayoutBlock(); - return null; + } else { + // We need the whole template model if the unique id is provided + const { data } = await this.itemRepository.requestItems([unique]); + if (data) { + this.#masterTemplate.setValue(data[0]); + } } - const { data } = await this.itemRepository.requestItems([id]); - if (data) { - this.#masterTemplate.setValue(data[0]); - this.#updateMasterTemplateLayoutBlock(); - return data[0]; - } - return null; + this.#updateMasterTemplateLayoutBlock(); + this._data.updateCurrent({ masterTemplate: unique ? { unique } : null }); + + return unique; } #updateMasterTemplateLayoutBlock = () => {