Unable to add children xblock

I’m trying to create custom Xblock which has multiple children. I was able to find info regarding rendering children Xblock.

But no clear guide on how to add children xblock to current xblock
.
Any help will be appreciated.

This has always been a bit of a strange thing. I’m not aware of an API that allows an XBlock to add new children to itself. OpenCraft has worked around this in the past by simply rendering HTML buttons like “Add Child Block X” in Studio with appropriate data elements, and when the user clicks on those buttons, Studio’s JS code will call Studio APIs to add new XBlock children.

The code for this is in StudioContainerXBlockMixin which you can use (AGPL) - here is an example.


BTW, I’m curious, what’s your use case? Some of us are thinking of moving the platform away from supporting XBlocks with other XBlocks as children in the long term, so I’d be interested to know.

POST call to http://localhost:18010/xblock/
with json data of {“category” : “xblockname”, “parent_locator” : “usageID of parent xblock”}

will create xblock and return
{ ‘locator’: “usage id of new xblock”, ‘courseKey’: “course key”)

There are custom created 3-4 xblocks by Team and we want to use them in other xblocks.

Thank you I was able to render xblocks added through api using these mixins

Ah yes. I meant that there is nothing within the XBlock (python) API to add a child block. There is of course a Studio REST API, otherwise it wouldn’t be possible to create courses :slight_smile:

Ohh sorry I misunderstood your words…
There was a need of adding child xblocks using studio view so had to use API