Hi dear community,
I’m currently implementing a Block Grid for editors so they can create an email template. I want to implement custom views for all these blocks, since they are relatively small and this gives editors a nice way to preview the template.
However, I ran into one issue:
One block contains a Block List, and I can’t figure out how to properly render the items with their custom block view.
Is there a component in Umbraco similar to <umb-block-grid-entries> that does the heavy lifting for me?
Component
import { customElement, property, html, LitElement } from "@umbraco-cms/backoffice/external/lit";
import { UmbElementMixin } from "@umbraco-cms/backoffice/element-api";
import { ContentBlock } from "./content-model";
import { newsletterBlockStyles } from "../style";
import { UmbBlockEditorCustomViewElement } from "@umbraco-cms/backoffice/block-custom-view";
@customElement("content-block-element")
export class ContentBlockElement
extends UmbElementMixin(LitElement)
implements UmbBlockEditorCustomViewElement
{
@property({ attribute: false })
content?: ContentBlock;
static styles = newsletterBlockStyles;
render() {
return html`
<table class="content" cellspacing="5" cellpadding="10" align="center">
<tbody>
${// or maybe call a component here that handles the blocklist context an renders the blocks?
this.content?.blocklist.contentData?.map((block) => {
// render the customview from the block itself
})}
</tbody>
</table>
`;
}
}
declare global {
interface HTMLElementTagNameMap {
"content-block-element": ContentBlockElement;
}
}
export default ContentBlockElement;
Model
import { UmbBlockDataType } from "@umbraco-cms/backoffice/block";
import { UmbBlockListValueModel } from "@umbraco-cms/backoffice/block-list";
export type ContentBlock = UmbBlockDataType & {
blocklist: UmbBlockListValueModel;
};