Enabling usage of Xblocks in Libraries (beta)

I’m relatively new to OpenEdX, I’ve installed an Xblock (specifically, the h5p one) into our tutor setup (21.0.8), and it seems to be working in that I can enable it in courses and the Xblock works fine there, but I cannot figure out how to enable it in the library. GitHub implies this should be possible , but I am struggling to find a docs page, forum post, or anything else that helps me figure out how to enable this functionality. Can anyone point me at the docs I’ve missed? Thanks!

:waving_hand: hi @Beth_Cimini and welcome to the community!! Thanks for reporting on your Tutor version :slight_smile:

Are you using this XBlock? GitHub - edly-io/h5pxblock: Xblock which provides ability to play H5P content in open edX · GitHub or a different one? Regardless, do you know what version you might have installed?

@braden or @kmccormick - any thoughts on this one?

Hi Sarina,

Yes, I’m using that block; I didn’t attempt to set up a specific version, just added it with OPENEDX_EXTRA_PIP_REQUIREMENTS, so I’m not certain, but I set up the server about a month ago so it’s presumably the latest release (0.2.18, from January), I can try to dig in more if you think that would help.

My overall setup stack was on a clean AWS - EC2 ubuntu 26.04, add Docker and pixi, then

pixi init && pixi add python && pixi add --pypi "tutor[full]" && pixi shell

#Below takes a while! (PWD is to get around pernicious "Docker compose can't access the config file" issue on EC2)

export TUTOR_ROOT=$PWD
tutor local launch

tutor config save --append OPENEDX_EXTRA_PIP_REQUIREMENTS=h5p-xblock
tutor images build openedx
tutor plugins enable cairn && tutor plugins enable credentials && tutor plugins enable deck && tutor plugins enable discovery && tutor plugins enable indigo && tutor plugins enable jupyter && tutor plugins enable notes
tutor local launch

We upgraded to 22.0.0 to see if that would resolve the issue - unfortunately, while we still can add in a course with the Xblock enabled (screenshot 1), we still see no way to add in the library (screenshot 2). Anything you can do to help us figure this out is appreciated!

Hi @Beth_Cimini In order to enable custom XBlocks on Libraries you need to add the XBlock name (same name you use on the Advanced Settings in courses) to the LIBRARY_ENABLED_BLOCKS setting, to do this you need to create a tutor plugin, here is minimal example on how you may do it:

from tutor import hooks

# Extra XBlocks to add to the Libraries V2 block picker
# (LIBRARY_ENABLED_BLOCKS in cms/envs/common.py).
# Replace these with your own custom block identifiers.
EXTRA_LIBRARY_BLOCKS = (
    "my-custom-xblock",
    "another-xblock",
)

hooks.Filters.ENV_PATCHES.add_item(
    (
        "openedx-cms-common-settings",
        f"""
_EXTRA_LIBRARY = {EXTRA_LIBRARY_BLOCKS!r}

# Append custom blocks that aren't already in the default list.
LIBRARY_ENABLED_BLOCKS = globals().get("LIBRARY_ENABLED_BLOCKS", [])
LIBRARY_ENABLED_BLOCKS += [
    b for b in _EXTRA_LIBRARY if b not in LIBRARY_ENABLED_BLOCKS
]
"""
    )
)

Drop this in a Tutor plugin file (e.g. my_extra_library_blocks.py) and it will inject the setting patch at CMS startup. Just swap the block identifiers in EXTRA_LIBRARY_BLOCKS for your actual xblock names.

PLEASE NOTE: In my experience, not all custom XBlocks work fine on the Libraries editor and may need code changes to work correctly there.

Thanks @rodrigo.mendez . I was able to add the plugin and add the h5pxblock to the library, but indeed if I try to use it to add an h5p file, it doesn’t quiiiiite work. (It uploads but never closes the save dialog to actually ADD the h5p). I’ve made a GH issue at the Xblock Git repo - thanks!