In this guide I will show you how to create your own XBlock based on the xblock-lti-consumer from edX. This can be very useful if you have a ubiquitous LTI resource that requires configuration.
Take for example a video conferencing app that is launched through LTI. If you want to add this app to your course, you would use the LTI Consumer XBlock and spend some time configuring it.
Forking LTI Consumer XBlock
An easy way to streamline this is to fork xblock-lti-consumer and use some inheritance magic 🧙♂️ so that we can add an LTI resource to our course without configuration.
In our fork, we need just make a few changes!
In lti_xblock.py, create a new class which inherits LtiConsumerXBlock
.
# lti_xblock.py
...
class MyXBlock(LtiConsumerXBlock):
display_name = String(
display_name=_("Display Name"),
help=_("Describe me..."),
scope=Scope.settings,
default=_("My Custom XBlock"),
)
What we just did is create a new XBlock, MyXBlock
. It is exactly the same as LtiConsumerXBlock
except for the display name.
Next, open setup.py and modify it like so
# setup.py
entry_points={
'xblock.v1': [
'lti_consumer = lti_consumer.lti_xblock:LtiConsumerXBlock',
'my_xblock = lti_consumer.lti_xblock: MyXBlock' # add this
],
...
},
Finally, in lti-consumer/__init__.py, add the following line
# lti_consumer/__init__.py
from .lti_xblock import MyXBlock
Wrapping Up
Now that we've created the XBlock, we can add it to a course by going to "Advanced Settings" and adding "my_xblock"
to the advanced module list.
You should now see "My Custom XBlock" in advanced components
Top comments (0)