DEV Community

Cover image for How to Extend the LTI Consumer XBlock (edX)
Michael Roudnitski
Michael Roudnitski

Posted on

How to Extend the LTI Consumer XBlock (edX)

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.

Screen Shot 2021-02-26 at 4.38.27 PM

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"),
     )
Enter fullscreen mode Exit fullscreen mode

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
    ],
    ...
},
Enter fullscreen mode Exit fullscreen mode

Finally, in lti-consumer/__init__.py, add the following line

# lti_consumer/__init__.py
from .lti_xblock import MyXBlock
Enter fullscreen mode Exit fullscreen mode

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.
Screen Shot 2021-02-26 at 5.13.46 PM

You should now see "My Custom XBlock" in advanced components
Screen Shot 2021-02-26 at 5.29.46 PM

Top comments (0)