LMSouq
moodle-core Open

Moodle : is it possible to access user from javascript ONLY

OV
Overdose
1 month ago
3 views
Problem Description
My purpose is simply being able to retrieve basic user info (id, username, lastname, firstname) in javascript on ANY moodle page WITHOUT having to create a plugin. I've seen that there is a javascript global variable in Moodle : `M` but no user info in there. Is there a way to access user info (id at least) from a logged in user on any page only in javascript another way ? I've tried the [generico filter][1] to create a block i would be able to retrieve information from <span data-firstname="@@USER:firstname@@" data-lastname="@@USER:lastname@@" data-userid="@@USER:id@@" id="useriddata"></span> But since i want it on any page, i've tried on the Moodle > Extra HTML textarea. Sadly it doesn't work since the HTML seems not to be filtered there. Creating a plugin for such a small information seems wrong. What can i do ? [1]: https://moodle.org/plugins/filter_generico

AI-Generated Solution

Powered by LMSouq AI · GPT-4.1-mini

✓ Solution Ready
Analyzing problem and generating solution…
Was this solution helpful?
Back to Knowledge Base