Change some quiz or question apparence

Change some quiz or question apparence

by olivier Dechepy -
Number of replies: 4

Hello Moodlers, 


I need to change the aspect of wether SOME quiz (the complete activity), SOME questions or its propositions : for quiz A, and C : the default theme is ok, but for quiz B, i want to display question differently for instance. The same goes for questions and propositions.

Theming Moodle adds weight (to load extra files) to verbosity of extra code.


Is already there a way to modify a quiz, a question or some proposition without asking the teacher to have any coding skill ?

What i an thinking is : there could just be an text field for the quiz, question or proposition setup where the teacher could add a given class. This is i this the easiest way to add a more granular customization.

With this, the theme designer would have prepared some custom css. The code would not be bloated by extra markup.


For instance : 

.thetrigger1 .qtext {margin-left: 2em;}

.thetrigger1 .answernumber {display:none}

etc


.thetrigger2 .qtext {background-color: red;}

.thetrigger2 .answernumber {background-color: orange}

etc


I hope i'm in the right forum : this tackles Quiz, Theme, Usabilty. Don't hesitate to move this if it's not the best choice.


Average of ratings: -
In reply to olivier Dechepy

Re: Change some quiz or question apparence

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
I don't think there is a way to do this.

There are lots of things that you can do, if you look at the list of classes that Moodle adds to the tag. That has things like the course id and the quiz cmid, and that lets you target styles at specific courses or activities. However, you have to maintain the list of ids in the style rules.

I suppose what you could do is add some JavaScript in the admin Additional HTML setting. Something like:
var styleControlElement = document.getElementById('style-control');
if (styleControlElement) {
    document.body.className += ' ' + styleControlElement.className
}

That would let the teacher add <span id="style-control" class="pink-quiz"> somewhere, and then when the page loads, "pink-quiz" would get added to the body tag. However, this is not really a full solution. E.g. you would need some security measure to stop students inputting that (e.g. in a forum post). But, the general idea might work with a bit more sophistication.

In reply to Tim Hunt

Re: Change some quiz or question apparence

by olivier Dechepy -
Thank you for the quick answer.
I was also thinking of using javascript, but it seems overkill for basic css control.
As you wrote, using existing css classes generated by the page isn't maintainable.

Except for en extra field in the quiz table (and potentially all activities tables), i don't think this is very intrusive.


I understand this is not a bug but a feature that would be beneficial to many i honestly think, so i will create a request on the tracker for this, unless someone else can point me to a plugin or another idea.
In reply to olivier Dechepy

Re: Change some quiz or question apparence

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
I don't think this should be specific to the quiz.

Whatever you do should work the same for any activity.