Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export class UmbTemplateWorkspaceEditorElement extends UmbLitElement {
}

#resetMasterTemplate() {
this.#templateWorkspaceContext?.setMasterTemplate(null);
this.#templateWorkspaceContext?.setMasterTemplate(null, true);
}

#openMasterTemplatePicker() {
Expand All @@ -121,7 +121,7 @@ export class UmbTemplateWorkspaceEditorElement extends UmbLitElement {
?.onSubmit()
.then((value) => {
if (!value?.selection) return;
this.#templateWorkspaceContext?.setMasterTemplate(value.selection[0] ?? null);
this.#templateWorkspaceContext?.setMasterTemplate(value.selection[0] ?? null, true);
})
.catch(() => undefined);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,15 @@ export class UmbTemplateWorkspaceContext

override async load(unique: string) {
const response = await super.load(unique);
await this.setMasterTemplate(response.data?.masterTemplate?.unique ?? null);

// On load we want to set the master template details but not update the layout block in the Razor file.
// This is because you can still set a layout in code by setting `Layout = "_Layout.cshtml";` in the template file.
// This gets set automatically if you create a template under a parent, but you don't have to do that, you can
// just set the `Layout` property in the Razor template file itself.
// So even if there's no master template set by there being a parent, there may still be one set in the Razor
// code, and we shouldn't overwrite it.
await this.setMasterTemplate(response.data?.masterTemplate?.unique ?? null, false);

return response;
}

Expand All @@ -79,9 +87,9 @@ export class UmbTemplateWorkspaceContext
},
});

// 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);
// On create set or reset the master template depending on whether the template is being created under a parent.
// This is important to reset when a new template is created so the UI reflects the correct state.
await this.setMasterTemplate(parent.unique, true);

return data;
}
Expand All @@ -102,7 +110,7 @@ export class UmbTemplateWorkspaceContext
return this.getData()?.content ? this.getLayoutBlockRegexPattern().test(this.getData()?.content as string) : false;
}

async setMasterTemplate(unique: string | null) {
async setMasterTemplate(unique: string | null, updateLayoutBlock: boolean) {
if (unique === null) {
this.#masterTemplate.setValue(null);
} else {
Expand All @@ -113,7 +121,10 @@ export class UmbTemplateWorkspaceContext
}
}

this.#updateMasterTemplateLayoutBlock();
if (updateLayoutBlock) {
this.#updateMasterTemplateLayoutBlock();
}

this._data.updateCurrent({ masterTemplate: unique ? { unique } : null });

return unique;
Expand Down
Loading