Skip to content

Commit 016f0d8

Browse files
Sofie Toft Kristensengitbook-bot
authored andcommitted
GITBOOK-24: Block Custom View Docs
1 parent d958e98 commit 016f0d8

File tree

4 files changed

+104
-28
lines changed

4 files changed

+104
-28
lines changed

15/umbraco-cms/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@
186186
* [Menu](customizing/extending-overview/extension-types/menu.md)
187187
* [Header Apps](customizing/extending-overview/extension-types/header-apps.md)
188188
* [Icons](customizing/extending-overview/extension-types/icons.md)
189+
* [Block Custom View](customizing/extending-overview/extension-types/block-custom-view.md)
189190
* [Bundle](customizing/extending-overview/extension-types/bundle.md)
190191
* [Kind](customizing/extending-overview/extension-types/kind.md)
191192
* [Backoffice Entry Point](customizing/extending-overview/extension-types/backoffice-entry-point.md)
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
---
2+
description: Bring your own representation for Blocks.
3+
---
4+
5+
# Block Custom View
6+
7+
The Block Custom View extension type lets you define a Web Component for representing blocks.
8+
9+
## Build a Custom View
10+
11+
1. Make a Document Type with a Property using a Block Editor of choice.
12+
2. Configure at least one Block Type on the Block Editor.
13+
3. Ensure the Element Type of the Blocks Content Model has a property using `headline` as the Property Alias.
14+
4. Take note of the Element Type Alias as you will use that in the next step.
15+
5. Add the following code to the `umbraco-package.json` file:
16+
17+
{% code title="umbraco-package.json" %}
18+
```json
19+
{
20+
"$schema": "../../umbraco-package-schema.json",
21+
"name": "My.CustomViewPackage",
22+
"version": "0.1.0",
23+
"extensions": [
24+
{
25+
"type": "blockEditorCustomView",
26+
"alias": "my.blockEditorCustomView.Example",
27+
"name": "My Example Custom View",
28+
"element": "/App_Plugins/welcome-dashboard/dist/example-block-custom-view.js",
29+
"forContentTypeAlias": "{Insert Element Type Alias here}"
30+
}
31+
]
32+
33+
```
34+
{% endcode %}
35+
36+
The code of your Web Component could look like this:
37+
38+
{% code title="example-custom-view.ts" %}
39+
```typescript
40+
import { html, customElement, LitElement, property, css } from '@umbraco-cms/backoffice/external/lit';
41+
import { UmbElementMixin } from '@umbraco-cms/backoffice/element-api';
42+
import type { UmbBlockDataType } from '@umbraco-cms/backoffice/block';
43+
import type { UmbBlockEditorCustomViewElement } from '@umbraco-cms/backoffice/block-custom-view';
44+
45+
@customElement('example-block-custom-view')
46+
export class ExampleBlockCustomView extends UmbElementMixin(LitElement) implements UmbBlockEditorCustomViewElement {
47+
48+
@property({ attribute: false })
49+
content?: UmbBlockDataType;
50+
51+
render() {
52+
return html`
53+
<h5>My Custom View</h5>
54+
<p>Headline: ${this.content?.headline}</p>
55+
`;
56+
}
57+
58+
static styles = [
59+
css`
60+
:host {
61+
display: block;
62+
height: 100%;
63+
box-sizing: border-box;
64+
background-color: darkgreen;
65+
color: white;
66+
border-radius: 9px;
67+
padding: 12px;
68+
}
69+
`,
70+
];
71+
72+
}
73+
export default ExampleBlockCustomView;
74+
75+
declare global {
76+
interface HTMLElementTagNameMap {
77+
'example-block-custom-view': ExampleBlockCustomView;
78+
}
79+
}
80+
81+
```
82+
{% endcode %}

15/umbraco-cms/fundamentals/backoffice/property-editors/built-in-umbraco-property-editors/block-editor/block-grid-editor.md

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ To set up the Block Grid property editor, follow these steps:
3737

3838
You will see the configuration options for a Block Grid property editor as shown below:
3939

40-
![Block Grid - Data Type Configuration](../../../../../../../10/umbraco-cms/fundamentals/backoffice/property-editors/built-in-property-editors/block-editor/images/BlockGridEditor\_Configuration.png)
40+
![Block Grid - Data Type Configuration](../../../../../../../10/umbraco-cms/fundamentals/backoffice/property-editors/built-in-property-editors/block-editor/images/BlockGridEditor_Configuration.png)
4141

4242
The Data Type editor allows you to configure the following properties:
4343

@@ -55,7 +55,7 @@ Block Types are based on [**Element Types**](../../../../data/defining-content/#
5555

5656
Once you have added an Element Type as a Block Type on your Block Grid Data Type you have the option to configure it.
5757

58-
![Block Grid - Data Type Block Configuration](../../../../../../../10/umbraco-cms/fundamentals/backoffice/property-editors/built-in-property-editors/block-editor/images/BlockGridEditor\_DataType\_Blocks.png)
58+
![Block Grid - Data Type Block Configuration](../../../../../../../10/umbraco-cms/fundamentals/backoffice/property-editors/built-in-property-editors/block-editor/images/BlockGridEditor_DataType_Blocks.png)
5959

6060
### Groups
6161

@@ -72,7 +72,7 @@ Customize the user experience for your content editors when they work with the B
7272
* **Label** - Defines a label for the appearance of the Block in the editor. The label can use AngularJS template-string-syntax to display values of properties.
7373

7474
{% hint style="info" %}
75-
Label example: "My Block \{=myPropertyAlias\}" will be shown as: "My Block FooBar".
75+
Label example: "My Block {=myPropertyAlias}" will be shown as: "My Block FooBar".
7676
{% endhint %}
7777

7878
* **Content model** - Presents the Element Type used as model for the Content section of this Block. This cannot be changed but you can open the Element Type to perform edits or view the properties available. Useful when writing your Label.
@@ -126,11 +126,11 @@ To scale an Area, click and drag the scale-button in the bottom-right corner of
126126
* **Grid Columns for Areas** - Overwrites the amount of columns used for the Area grid.
127127
* **Areas** - Determines whether the Block can be created inside Areas of other Blocks.
128128

129-
![Block Grid - Areas](../../../../../../../10/umbraco-cms/fundamentals/backoffice/property-editors/built-in-property-editors/block-editor/images/BlockGridEditor\_Areas.png)
129+
![Block Grid - Areas](../../../../../../../10/umbraco-cms/fundamentals/backoffice/property-editors/built-in-property-editors/block-editor/images/BlockGridEditor_Areas.png)
130130

131131
### Area configuration
132132

133-
![Block Grid - Area Configuration](../../../../../../../10/umbraco-cms/fundamentals/backoffice/property-editors/built-in-property-editors/block-editor/images/BlockGridEditor\_AreasConfiguration.png)
133+
![Block Grid - Area Configuration](../../../../../../../10/umbraco-cms/fundamentals/backoffice/property-editors/built-in-property-editors/block-editor/images/BlockGridEditor_AreasConfiguration.png)
134134

135135
* **Alias** - The alias is used to identify this Area. It is being printed by `GetBlockGridHTML()` and used as name for the Area slot in Custom Views. The alias is also available for CSS Selectors to target the HTML-Element representing an Area.
136136
* **Create Button Label** - Overwrites the Create Button Label of the Area.
@@ -157,33 +157,33 @@ Notice that any styling of a Block is scoped. This means that the default backof
157157

158158
When viewing a **Block Grid** property editor in the **Content** section for the first time, you will be presented with the option to **Add content**.
159159

160-
![Block Grid - Add Content](../../../../../../../10/umbraco-cms/fundamentals/backoffice/property-editors/built-in-property-editors/block-editor/images/BlockGridEditor\_AddContent.png)
160+
![Block Grid - Add Content](../../../../../../../10/umbraco-cms/fundamentals/backoffice/property-editors/built-in-property-editors/block-editor/images/BlockGridEditor_AddContent.png)
161161

162162
Clicking the **Add content** button opens up the **Block Catalogue**.
163163

164-
![Block Grid - Setup](../../../../../../../10/umbraco-cms/fundamentals/backoffice/property-editors/built-in-property-editors/block-editor/images/BlockGridEditor\_BlockPicker.png)
164+
![Block Grid - Setup](../../../../../../../10/umbraco-cms/fundamentals/backoffice/property-editors/built-in-property-editors/block-editor/images/BlockGridEditor_BlockPicker.png)
165165

166166
The Block Catalogue looks different depending on the amount of available Blocks and their catalogue appearance.
167167

168-
![Block Grid - example setup](../../../../../../../10/umbraco-cms/fundamentals/backoffice/property-editors/built-in-property-editors/block-editor/images/BlockGridEditor\_BlockPicker\_exsetup.png)
168+
![Block Grid - example setup](../../../../../../../10/umbraco-cms/fundamentals/backoffice/property-editors/built-in-property-editors/block-editor/images/BlockGridEditor_BlockPicker_exsetup.png)
169169

170170
Click the Block Type you wish to create and a new Block will appear in the layout.
171171

172172
More Blocks can be added to the layout by clicking the Add content button. Alternatively, use the Add content button that appears on hover to add new Blocks between, besides, or above the existing Blocks.
173173

174-
![Block Grid - Add Content Inline](../../../../../../../10/umbraco-cms/fundamentals/backoffice/property-editors/built-in-property-editors/block-editor/images/BlockGridEditor\_AddContentInline.png)
174+
![Block Grid - Add Content Inline](../../../../../../../10/umbraco-cms/fundamentals/backoffice/property-editors/built-in-property-editors/block-editor/images/BlockGridEditor_AddContentInline.png)
175175

176176
To delete a Block, click the trash icon which appears on the mouse hover.
177177

178-
![Block Grid - Delete Content](../../../../../../../10/umbraco-cms/fundamentals/backoffice/property-editors/built-in-property-editors/block-editor/images/BlockGridEditor\_DeleteContent.png)
178+
![Block Grid - Delete Content](../../../../../../../10/umbraco-cms/fundamentals/backoffice/property-editors/built-in-property-editors/block-editor/images/BlockGridEditor_DeleteContent.png)
179179

180180
## Sorting Blocks
181181

182182
Blocks can be rearranged using the click and drag feature. Move them up or down to place them in the desired order.
183183

184184
Moving a Block from one Area to another is done in the same way. If a Block is not allowed in the given position, the area will display a red color and not allow the new position.
185185

186-
![Block Grid - Sorting Blocks](../../../../../../../10/umbraco-cms/fundamentals/backoffice/property-editors/built-in-property-editors/block-editor/images/Sorting\_BlockGrid\_Blocks.gif)
186+
![Block Grid - Sorting Blocks](../../../../../../../10/umbraco-cms/fundamentals/backoffice/property-editors/built-in-property-editors/block-editor/images/Sorting_BlockGrid_Blocks.gif)
187187

188188
## Scaling Blocks
189189

@@ -452,7 +452,7 @@ For example: You can use the below HTML structure:
452452

453453
Building Custom Views for Block representations in Backoffice is based on the same API for all Block Editors.
454454

455-
[Read about building a Custom View for Blocks here](build-custom-view-for-blocks.md)
455+
[Read about building a Custom View for Blocks here](../../../../../customizing/extending-overview/extension-types/block-custom-view.md)
456456

457457
## Creating a Block Grid programmatically
458458

@@ -540,7 +540,6 @@ All `contentData` and `layoutData` entries need their own unique `Udi` as well a
540540
8. First and foremost, we need models to transform the raw data into Block Grid compatible JSON. Create a class called **Model.cs** containing the following:
541541

542542
{% code title="Models.cs" lineNumbers="true" %}
543-
544543
```csharp
545544
using Umbraco.Cms.Core;
546545
using System.Text.Json.Serialization;
@@ -623,13 +622,11 @@ public class BlockGridElementData
623622
public Dictionary<string, object>? Data { get; set;}
624623
}
625624
```
626-
627625
{% endcode %}
628626

629627
9. By injecting [ContentService](https://apidocs.umbraco.com/v15/csharp/api/Umbraco.Cms.Core.Services.ContentService.html) and [ContentTypeService](https://apidocs.umbraco.com/v15/csharp/api/Umbraco.Cms.Core.Services.ContentTypeService.html) into an API controller, we can transform the raw data into Block Grid JSON. It can then be saved to the target content item. Create a class called **BlockGridTestController.cs** containing the following:
630628

631629
{% code title="BlockGridTestController.cs" lineNumbers="true" %}
632-
633630
```csharp
634631
using Microsoft.AspNetCore.Mvc;
635632
using My.Site.Models;

15/umbraco-cms/fundamentals/backoffice/property-editors/built-in-umbraco-property-editors/block-editor/block-list-editor.md

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ To set up your Block List Editor property, create a new _Data Type_ and select *
2424

2525
Then you will see the configuration options for a Block List as shown below.
2626

27-
![Block List - Data Type Definition](../../../../../../../10/umbraco-cms/fundamentals/backoffice/property-editors/built-in-property-editors/block-editor/images/BlockListEditor\_DataType.jpg)
27+
![Block List - Data Type Definition](../../../../../../../10/umbraco-cms/fundamentals/backoffice/property-editors/built-in-property-editors/block-editor/images/BlockListEditor_DataType.jpg)
2828

2929
The Data Type editor allows you to configure the following properties:
3030

@@ -41,7 +41,7 @@ Block Types are **Element Types** which need to be created before you can start
4141

4242
Once you have added an element type as a Block Type on your Block List Data Type you will have the option to configure it further.
4343

44-
![Block List - Data Type Block Configuration](../../../../../../../10/umbraco-cms/fundamentals/backoffice/property-editors/built-in-property-editors/block-editor/images/BlockListEditor\_DataType\_Blocks.png)
44+
![Block List - Data Type Block Configuration](../../../../../../../10/umbraco-cms/fundamentals/backoffice/property-editors/built-in-property-editors/block-editor/images/BlockListEditor_DataType_Blocks.png)
4545

4646
Each Block has a set of properties that are optional to configure. They are described below.
4747

@@ -81,31 +81,31 @@ These properties are relevant when you work with custom views.
8181

8282
When viewing a **Block List** editor in the Content section for the first time, you will be presented with the option to Add content.
8383

84-
![Block List - Add Content](../../../../../../../10/umbraco-cms/fundamentals/backoffice/property-editors/built-in-property-editors/block-editor/images/BlockListEditor\_AddContent.png)
84+
![Block List - Add Content](../../../../../../../10/umbraco-cms/fundamentals/backoffice/property-editors/built-in-property-editors/block-editor/images/BlockListEditor_AddContent.png)
8585

8686
Clicking the Add content button brings up the Block Catalogue.
8787

88-
![Block List - Setup](../../../../../../../10/umbraco-cms/fundamentals/backoffice/property-editors/built-in-property-editors/block-editor/images/BlockListEditor\_BlockPicker\_simplesetup.jpg)
88+
![Block List - Setup](../../../../../../../10/umbraco-cms/fundamentals/backoffice/property-editors/built-in-property-editors/block-editor/images/BlockListEditor_BlockPicker_simplesetup.jpg)
8989

9090
The Block Catalogue looks different depending on the amount of available Blocks and their catalogue appearance.
9191

92-
![Block List - example setup from Umbraco.com](../../../../../../../10/umbraco-cms/fundamentals/backoffice/property-editors/built-in-property-editors/block-editor/images/BlockListEditor\_BlockPicker.jpg)
92+
![Block List - example setup from Umbraco.com](../../../../../../../10/umbraco-cms/fundamentals/backoffice/property-editors/built-in-property-editors/block-editor/images/BlockListEditor_BlockPicker.jpg)
9393

9494
Click the Block Type you wish to create and a new Block will appear in the list.
9595

9696
Depending on whether your Block List Editor is setup to use default or inline editing mode you will see one of the following things happening:
9797

9898
In default mode you will enter the editing overlay of that Block:
9999

100-
![Block List - Overlay editing](../../../../../../../10/umbraco-cms/fundamentals/backoffice/property-editors/built-in-property-editors/block-editor/images/BlockListEditor\_EditingOverlay.jpg)
100+
![Block List - Overlay editing](../../../../../../../10/umbraco-cms/fundamentals/backoffice/property-editors/built-in-property-editors/block-editor/images/BlockListEditor_EditingOverlay.jpg)
101101

102102
In inline editing mode the new Blocks will expand to show its inline editor:
103103

104-
![Block List - Inline editing](../../../../../../../10/umbraco-cms/fundamentals/backoffice/property-editors/built-in-property-editors/block-editor/images/BlockListEditor\_InlineEditing.jpg)
104+
![Block List - Inline editing](../../../../../../../10/umbraco-cms/fundamentals/backoffice/property-editors/built-in-property-editors/block-editor/images/BlockListEditor_InlineEditing.jpg)
105105

106106
More Blocks can be added to the list by clicking the Add content button or using the inline Add content button that appears on hover between or above existing Blocks.
107107

108-
![Block List - Add Content](../../../../../../../10/umbraco-cms/fundamentals/backoffice/property-editors/built-in-property-editors/block-editor/images/BlockListEditor\_AddContentInline.jpg)
108+
![Block List - Add Content](../../../../../../../10/umbraco-cms/fundamentals/backoffice/property-editors/built-in-property-editors/block-editor/images/BlockListEditor_AddContentInline.jpg)
109109

110110
To reorder the Blocks, click and drag a Block up or down to place in the desired order.
111111

@@ -164,10 +164,6 @@ With ModelsBuilder:
164164
<h1>@content.Heading</h1>
165165
```
166166

167-
{% embed url="<https://www.youtube.com/watch?ab_channel=UmbracoLearningBase&v=ltZTgfIoCtg>" %}
168-
Working with Block List Editor in Umbraco
169-
{% endembed %}
170-
171167
### 2. Build your own rendering
172168

173169
A built-in value converter is available to use the data as you like. Call the `Value<T>` method with a generic type of `IEnumerable<BlockListItem>` and the stored value will be returned as a list of `BlockListItem` entities.
@@ -251,4 +247,4 @@ If you know the Block List Editor only uses a single block, you can cast the col
251247

252248
## Build a Custom Backoffice View
253249

254-
Building Custom Views for Block representations in Backoffice is the same for all Block Editors. [Read about building a Custom View for Blocks here](build-custom-view-for-blocks.md)
250+
Building Custom Views for Block representations in Backoffice is the same for all Block Editors. [Read about building a Custom View for Blocks here](../../../../../customizing/extending-overview/extension-types/block-custom-view.md)

0 commit comments

Comments
 (0)