Develop Secure Code
getCurrentSelectedBlock
replaceBlock
getCurrentSelectedBlockRetrieves the JSON structure of a selected component on the canvas of a marketing content item. Use this wire adapter when building a CMS extension for Marketing Cloud Next that interacts with components on the canvas.
1import { LightningElement, wire, api } from "lwc";
2import { getCurrentSelectedBlock } from "experience/blockBuilderApi";
3
4export default class Example extends LightningElement {
5 @api paragraphText;
6
7 @wire(getCurrentSelectedBlock, {})
8 onCurrentSelectedBlock({ data }) {
9 if (data) {
10 const selectedBlockInUEMFormat = data;
11
12 // check the type of the block
13 const blockDefinition = selectedBlockInUEMFormat.definition;
14
15 // handle a paragraph block
16 if (blockDefinition === "lightning/paragraph") {
17 const paragraphBlock = selectedBlockInUEMFormat;
18
19 // extract the text attribute from the paragraph block
20 this.paragraphText = paragraphBlock.attributes.text;
21 }
22
23 // do other things with the block...
24 } else {
25 // no block is currently selected
26 this.paragraphText = "";
27 }
28 }
29}data—the JSON structure of the selected component. Undefined if the user hasn’t selected a component.Release Preview