Block Custom View
Create a custom Web Component to visually represent blocks in Umbraco's Block editors.
The Block Custom View extension type allows you to define a custom Web Component to visually represent blocks (for example: Block List, Block Grid).
Build a Custom View
Create a Document Type with a property that uses a Block Editor.
Configure at least one Block Type on the Block Editor.
Make sure the Element Type used as the block's Content Model has properties you want to display. For example, a property with alias
headline.Note the Element Type Alias. You will need it shortly.
(Optional) Create a Settings Model for the above Element Type if you want to include settings data. For example, add a property with alias
theme.Register the custom view in
umbraco-package.jsonfile:
{
"$schema": "../../umbraco-package-schema.json",
"name": "My.CustomViewPackage",
"version": "0.1.0",
"extensions": [
{
"type": "blockEditorCustomView",
"alias": "my.blockEditorCustomView.Example",
"name": "My Example Custom View",
"element": "/App_Plugins/block-custom-view/dist/example-block-custom-view.js",
"forContentTypeAlias": "myElementTypeAlias", // your Element Type Alias from Step 4 (e.g. "myHeroBlock")
"forBlockEditor": "block-list" // insert block editor type here: "block-list" or "block-grid"
}
]
}The Web Component
The code of your Web Component could look like this:
The TypeScript component (ExampleBlockCustomView) implements UmbBlockEditorCustomViewElement and receives the following reactive properties:
content— the block's content data (for example,this.content?.headline)settings— the block's settings data, if a Settings Model is configured (for example,this.settings?.theme)
These map directly to the properties defined on the Element Type and its Settings Model (if configured).
Last updated
Was this helpful?