Get user picture in CSS

Get user picture in CSS

by Richard van Iwaarden -
Number of replies: 5
Picture of Particularly helpful Moodlers

Is there any way to get the user-picture with CSS?

    background-image: url(http://moodle.org/pluginfile.php/7284/user/icon/theme/f1);


How can I make it so that i get the picture of the current logged in user with CSS?

Or is there another way? (note: I can not change PHP files as we have a hosted Moodle)

Average of ratings: -
In reply to Richard van Iwaarden

Re: Get user picture in CSS

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

If you tell me the name of the theme you are using and the version of Moodle, I may be able to advise you what to do.

In reply to Mary Evans

Re: Get user picture in CSS

by Richard van Iwaarden -
Picture of Particularly helpful Moodlers
Thanks Mary.


Theme is Pioneer v1.4.3.1 

Moodle version is Moodle 3.1.2+ (Build: 20160923) 


Both will probably be updated tonight to latest version of Pioneer and Moodle 3.2.2.

In reply to Mary Evans

Re: Get user picture in CSS

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Just realised that you have asked this question before...however...since you cannot change anything in the themes files then the only solution I can suggest is for me to alter the Pioneer theme and add the user image in the layout file or files depending on how the Pioneer theme is built.

Then all you would need to do is

  1. change theme to Clean theme
  2. uninstall the Pioneer theme Site Administration > Plugins > Plugins overview
  3. install the updated theme via Site Administration > Plugins > Install plugins

The only downfall with this is that you will lose the settings that are in place now.

Cheers

Mary

In reply to Richard van Iwaarden

Re: Get user picture in CSS

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Given "How can I make it so that i get the picture of the current logged in user with CSS?" then it cannot be done because:

Theme CSS is a 'static' thing in comparison with the dynamic nature of user sessions.  Thus the theme CSS is created (one for LTR and another for RTL) for all users.  Therefore any CSS setting / theme change to the CSS would mean a rebuild of the whole CSS per user per page load, same as having TDM off.

Therefore the only solution theme wise would be inline CSS somewhere in the markup, but then just use an 'img' tag instead.

In reply to Gareth J Barnard

Re: Get user picture in CSS

by Richard van Iwaarden -
Picture of Particularly helpful Moodlers

However... I could do it with javascript smile

Let me try that. I should be able to get the element by ID or something.


What I'm trying to do is get a user picture top left and around that user  picture the course progress.


Should look like this:



Average of ratings: Useful (1)