An XBlock can have child XBlocks.
An XBlock does not refer directly to its children. Instead, the structure of a tree of XBlocks is maintained by the runtime application, and is made available to the XBlock through a runtime service. For more information, see XBlock Runtimes.
This allows the runtime to store, access, and modify the structure of a course without incurring the overhead of the XBlock code itself.
XBlock children are not implicitly available to their parents. The runtime
provides the parent XBlock with a list of child XBlock IDs. The child XBlock
can then be loaded with the
get_child() function. Therefore the runtime can
defer loading child XBlocks until they are actually required.
To access XBlock children through the server, use the following methods.
self.get_childrenwhich returns the IDs for each child XBlock.
self.get_child(usage_id)for your desired ID. You can then modify the child XBlock using its
fragment.contentinto the parent XBlock’s HTML file, then use
elementis the DOM node that contains the HTML representation of your XBlock’s server-side view. (
runtimeis automatically provided by the XBlock runtime.)
runtime.childMap(element, name)to get a child element that has a specific name.