Learner data in OLX script tag

How can I access data about the learner taking a course from inside an OLX tag?

I’d like to use their user id to pull data customized for them and the problem from a remote server. I can get data from a remote server but I don’t know how to get info about the user to pass to the server. Thanks

Hi @pdebruic,

In Text/HTML components (but not any other type), you can include %%USER_ID%% in the HTML, and it will be replaced with a unique but anonymized user identifier for that user. I don’t think there’s a similar way to get the user’s real ID nor username, however.

Code reference: https://github.com/edx/edx-platform/blob/efef7d81ee860bef49b4cc8eeb71fccdd3ae7dc0/common/lib/xmodule/xmodule/html_module.py#L120

1 Like

OK thanks. IS the user’s real first name something an xblock could provide?

The Open edX platform generally doesn’t store users’ first names, but rather just their full name, as recommended by the W3C.

XBlocks can get the user’s full name using

@XBlock.needs('user')
...
self.runtime.service(self, 'user').get_current_user().full_name

You could try to split that up to guess first name / last name, but you can’t do that reliably with names like “Mary Jane Smith” and “Alice De Jong”.