In this example, we will show you how to use the CreativeEditor SDK’s CreativeEngine to modify the hierarchy of blocks through the block
API.
Manipulate the hierarchy of blocks
fun getParent(block: DesignBlock): DesignBlock?
Query a block’s parent.
-
block
: the block to query. -
Returns the parent’s handle or null if the block has no parent.
fun getChildren(block: DesignBlock): List<DesignBlock>
Get all children of the given block. Children are sorted in their rendering order:
Last child is rendered in front of other children.
-
block
: the block to query. -
Returns a list of block ids.
fun insertChild( parent: DesignBlock, child: DesignBlock, index: Int,)
Insert a new or existing child at a certain position in the parent’s children.
Required scope: “editor/add”
-
parent
: the block to update. -
child
: the child to insert. Can be an existing child ofparent
. -
index
: the index to insert or move to.
fun appendChild( parent: DesignBlock, child: DesignBlock,)
Appends a new or existing child to a block’s children.
Required scope: “editor/add”
-
parent
: the block to update. -
child
: the child to insert. Can be an existing child ofparent
.
When adding a block to a new parent, it is automatically removed from its previous parent.
Full Code
Here’s the full code:
engine.block.insertChild(parent = page, child = block, index = 0)val parent = engine.block.getParent(block)val childIds = engine.block.getChildren(block)engine.block.appendChild(parent = parent, child = block)