Child themes of Boost

Child themes of Boost

by Jamie Tinley -
Number of replies: 32

Hi I'm hoping Mary or someone else can enlighten me after 20 years of being an admin on an easier way than what I've been doing. I just updated to moodle 3.7. In 3.4 I used boost and made about 10 child themes of boost each in a different color and now in 3.7 none of them work of course so I have to repeat the process in notepad searching for all occurrences of the theme name Etc and making those changes again which I can easily do but I'm thinking there must be an easier way for my teachers to be able to have a different color background to their course without me having to make these child themes every single time Moodle updates. please enlighten me as there must be an easier way to have consistency in all courses (ie same theme) but different colors. Ive tried uploading different themes in the past which is quick but then they are not consistent for users and its easier to work with one theme for me as if there is an issue I know it will affect all my child color themes in the same way. Thank you smile

Average of ratings: -
In reply to Jamie Tinley

Re: Child themes of Boost

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers

The reason they are not working is the significant changes in Boost between Moodle3.4 and 3.7 - but you probably already realised that smile

There is another way to do this:

in the body classes (certainly if you enable use course themes, I can't remember if its there anyway), you will see a class for the course id, eg (from one of my development sites).

<body  id="page-course-view-topcoll" class="format-topcoll  path-course path-course-view gecko dir-ltr
lang-en yui-skin-sam yui3-skin-sam moodle-dev-glos-ac-uk--moodledev pagelayout-course course-24639 context-644294
category-6352 category-6295 category-6266 category-6265 Jul24 showforsemester drawer-open-left">

You can use that course id class to target specific css in either a custom scss file, or in one of the Boost CSS/SCSS settings.


Average of ratings: Useful (1)
In reply to Richard Oelmann

Re: Child themes of Boost

by Jamie Tinley -

Thanks Richard. I wondered if css could do it. Ive only pasted other peoples css like Marys but never been able to understand how to write it.


Can you show me an example of how I could do blue green pink tan Etc four different courses and let the teacher choose from a drop-down thank you

In reply to Jamie Tinley

Re: Child themes of Boost

by Jamie Tinley -

I'm thinking there must be an easier way for my teachers to just change only the background color of boost by Moodle 3.7 than either using css or me cteating child themes. 

I am hoping ive been missing somethig simple in administration I can select to allow teachers to say have blue boost for one course but geen boost for another course and tan for another etc. Ive read the cdocumentation and searched forums for years but I dont yet srr an easier way. Thanks for anyone's insight

In reply to Jamie Tinley

Re: Child themes of Boost

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers
Sorry Jamie, I thought I'd replied to this, but obviously not...

One way to do this would be to make use of the new custom course settings in 3.7 https://docs.moodle.org/37/en/Course_settings#Course_custom_fields
Create a custom course setting that teachers can use to select a colour scheme, then in your layout file use a conditional statement to detect that custom field and apply a body class based on it.

Below is an example from when I was first experimenting on this approach when I first saw these custom course fields - there may be better ways to access the setting and more than happy for someone to point that out if there are!

$extraclasses = [];
// Experimental course field settings.
// -----------------------------------
if ($DB->record_exists('customfield_field', array('shortname' => 'darkheading'))) {
$cff = $DB->get_record('customfield_field', array('shortname' => 'darkheading'));
if ($DB->record_exists('customfield_data', array('fieldid' => $cff->id, 'instanceid' => $COURSE->id))) {
$drkhd = $DB->get_record('customfield_data', array('fieldid' => $cff->id, 'instanceid' => $COURSE->id));
if ($drkhd->value ==1) {
$extraclasses[] = 'darkheading';
}
}
}
$bodyattributes = $OUTPUT->body_attributes($extraclasses);

Then your scss can target that new body class to set the details of your look and feel for that option.

Richard
In reply to Richard Oelmann

Re: Child themes of Boost

by Jamie Tinley -
Thank you for all your explanations Richard you're obviously a Guru and it's going to take me a little while to read and re read this to figure it out. If you ever do a tutorial on YouTube I would love to see it. Thanks Jamie
In reply to Richard Oelmann

Re: Child themes of Boost

by Jamie Tinley -
Custom course fieldThanks Richard that's acool new feature. I read the documentation 2x and am confused where to paste your code. See screenshot. I tried course custom field then added a droodown box but where do I post your code and then how can I make some basic background color choices?

Thank you SO much for helping show this great solution.

In reply to Jamie Tinley

Re: Child themes of Boost

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers

OK, firstly as this goes beyond simply adding css to a setting block this should really be done in either a clone or child theme of Boost as anything you do in Boost itself will get overwritten on any future upgrade.
In your theme, copy the layout file column2.php and rename as courses.php, then adjust the theme config.php to point to that layout file for course and incourse page types and add code as in Waxed example https://gitlab.com/ro-mdl-themes/moodle-theme_waxed/blob/master/layout/courses.php#L40-48
You then need to add whatever styles you want to your scss preset, something like

body.colsch_2{background-color:rgba(0,0,33,0.8);}
.colsch_2 #region-main{font-weight:700;color:rgb(0,0,33);}
body.colsch_3{background-color:rgba(0,33,0,0.8);}
.colsch_3 #region-main{font-weight:700;color:rgb(0,33,0);}
//These are not intended to be genuine colours/design choices, just examples of the selectors!

Alternatively, you could download and use Waxed (from git - I haven't yet pushed this addition to the themes database). Waxed is a fairly basic child of Boost that I created with the intention of adding simple additional features like this, rather than adding multiple big features the way some of the more powerful themes do smile

Or you could just take a look at how I've added it there to add to your own theme

https://gitlab.com/ro-mdl-themes/moodle-theme_waxed/commit/428fce37839d620f62e168197adbd791eb936c61

Note: Waxed does not yet have any styles added to its presets, it only has this layout code added to add the relevant body class and associated changes to config.php.

Hope that helps.


Edit - correction to css: the code outputs the value as the number of the option in the dropdown, not the text, so either you can use the value as I have above, or you can adapt the code to grab something more readable along the lines of

(pseudo code)

if value=1 then class='colsch_blue'

if value=2 then class='colsch_green'

In reply to Jamie Tinley

Re: Child themes of Boost

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

May I ask if you have a child theme of Boost or in fact Adaptable given the screen shot?

G
In reply to Gareth J Barnard

Re: Child themes of Boost

by Jamie Tinley -

Hi Gareth you are correct this is adaptable because this is my new install moodle 3.7 my previous install of 3.4 had child themes of boost and also used your main theme of essential which sadly is not continuing and I understand why I appreciate your past service to that theme which I used for many years. I can create child themes again and Richard is giving me a way to do it easier than the way I did in the past but it's going to take me a while to wrap my head around all this css code. I'm surprised after so many years there's not an easier way in Moodle to just have some basic color schemes without having to install new themes or create child athemes or use CSS code. Thanks

In reply to Jamie Tinley

Re: Child themes of Boost

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers
Well, the layout code is now in Waxed, so if you use that, then all you really need to do is decide the css you want for each of the options, which can be created as a preset and uploaded in the Waxed setting, or can be written into the customscss setting in Waxed. Then you add the drop down as a course custom field.
You could, if you prefer, ask someone to create the preset for you (providing a pdf/screenshot and description) if you're not comfortable with the css.

Hmmm - having put the layout code in, going to have a think about the preset side of it. But this may take a few weeks Jamie as I'm on the final countdown to annual updates of my work Moodle and Mahara sites over the next couple of weeks.

The primary issue with different colour schemes for different courses, or users/etc within a single theme has always been the fact that the css generated in Moodle is cached, so you have to have it all there in the css and then use classes to apply it. You can't apply, say preset1 to courseA and preset2 to courseB.
In reply to Richard Oelmann

Re: Child themes of Boost

by Jamie Tinley -

Thanks Richard I will try it with waxed then if I fail 3 weeks is nothing compared to the last 15 years of struggling to best serve my users. Thanks

In reply to Jamie Tinley

Re: Child themes of Boost

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers
No need to fail smile Just try and then ask for more support saying where you are stuck smile

The layout code should be there (github only at the moment)
So add a dropdown course setting - Personally I'd go None, blue, green, tan, pink - following your earlier examples of what you want - and make the default setting 'none'.

Then in the RawSCSS setting box at the bottom of the page, try something like:

.colsch_2 #page, .colsch_2 #region-main {background-color: #78CBFC;}
.colsch_3 #page, .colsch_3 #region-main {background-color: #AAFDBC;}
.colsch_4 #page, .colsch_4 #region-main {background-color: #FFCD7F;}
.colsch_4 #page, .colsch_4 #region-main {background-color: #FF8E9E;}

Once you can see that working, it really is just a case of the design and the colours you want. Use Firefox or Chrome Inspect Element tools to find the appropriate selector to apply your css to - You can even test it in FF/Chrome developer tools then copy to Waxed>RawSCSS.
Only when you have everything set as you want it, copy it to a preset - or leave it in the RawSCSSS setting if you prefer. It's easier to edit in the setting smile

Note the body class colsch_1 would be for none and you don't need to add any additional css for that, its just there to ensure there's a default on the drop down as I haven't written much in the way of error catching (or done much testing) into the code, its just fairly quick and dirty smile but it is working on my localhost - but let me know if you do get any errors and I'll happily look into it for you.

In case you're interested, the other option I've added on my work theme - I'll try to add it into Waxed later on if I can - is to add some simple user choice grey-scale options. These are based on a user profile field, and simply apply a filter based on another body class... (We previously had a quite bright, multicoloured theme, based on the university's marketing colours and it created some accessibility issues because of the range of colours)

.greyscale {filter: grayscale(90%);}
.invertedgreyscale {filter: grayscale(100%) invert(100%);}
.bonw {filter: grayscale(100%) brightness(80%) contrast(200%);}
.invertedbonw {filter: grayscale(100%) brightness(80%) contrast(200%) invert(100%);}


R

In reply to Richard Oelmann

Re: Child themes of Boost

by Jamie Tinley -
Custom Course SettingWaxed Raw SCSSHi Richard,

My understanding at this point is there are 3 steps.
1. layout code - already provided by you from your github repo which is what I used so I assume that step is done
2. custom drop down course setting. I created this with 3 colors so far but HOW does it connect blue or green to the scss code. I am missing where this if - then statement goes.
3. add in the Raw SCSS code ( in Colours tab at bottom. what's the Raw Initial SCSS code for?)
I included screenshots of what I did and I see the teacher can click other and see my color choices I just don't get how it connects to your SCSS code.
Thanks!
In reply to Jamie Tinley

Re: Child themes of Boost

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers

The conditional is already in the courses.php layout file - I need to adjust the comment in it as it doesn't add colsch_blue, colsch_green, but the colsch_1, colsch_2 etc.

https://gitlab.com/ro-mdl-themes/moodle-theme_waxed/blob/master/layout/courses.php#L41-49

They come from the dropdown and are recorded as numeric values rather than the text value of the dropdown, so in your example Blue would be colsch_1, Green would be colsch_2 and Tan would be colsch_3.

I added a None as the default option in my original example, as although you could leave it unset, I wanted to have a way of removing any previously set colour option too, so selecting None in my example would give a body class that has no additional styles associated with it.

The only reason to adjust the conditional I've included in courses.php would be if you wanted to make those classes more readable

If value=1 add class colsch_blue, if value=2 add colsch_green, etc.


Oh - and there should only have been one colsch_4 line in my example scss! Oops smile

In reply to Richard Oelmann

Re: Child themes of Boost

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers
Probably something like (from L45):

if ($DB->record_exists('customfield_data', array('fieldid' => $cff->id, 'instanceid' => $COURSE->id))) {
   $colsch = $DB->get_record('customfield_data', array('fieldid' => $cff->id, 'instanceid' => $COURSE->id));
   $extraclasses[] = 'colsch_'.$colsch->value;
  switch($colsch->value) {
    case "1":
      $extraclasses[] = 'colsch_blue';
      break;
    case "2":
      $extraclasses[] = 'colsch_green';
      break;
    case "3":
      $extraclasses[] = 'colsch_tan';
      break;
    default:
      // No extra classes.
  }
}
In reply to Richard Oelmann

Re: Child themes of Boost

by Jamie Tinley -
Thanks Richard, so am I supposed to put this extra code below Line 45 in courses.php? I created the custom drop down list but no matter which one I choose when on the waxed theme it still looks the same as any other choice. Also I changed .colsch_4 #page, .colsch_4 #region-main {background-color: #FF8E9E;} to .colsch_5 #page, .colsch_5 #region-main {background-color: #FF8E9E;}
and added up to .colsch_9 : is there any limit to the number I can add or does the code assume 3 choices?
Also how is .colsch_2 #page, .colsch_2 #region-main {background-color: #78CBFC;}
going to code for none when #78CBFC means blue? should I put a .colch_1 in there that somehow tells it not to put on any css? How?

also can I use these Hex numbers from the link here or are they different?: 
In reply to Jamie Tinley

Re: Child themes of Boost

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers
On my original example
None -> colsch_1
Blue -> colsch_2
Green -> colsch_3
Tan -> colsch_4
Pink -> colsch_5
If you're happy using those numbers instead of colsch_blue, colsch_green, etc, then you don't need to add any additional code to what is already in waxed. Personally, I would stick with the numbers - it leaves the code more flexible if you want to add more options later on (or remove them). You could always add a comment line in your css identifying number->colour, for readablity.

You don't need to add any css for colsch_1 (None), it is literally there to allow a reset to normal, with no additional css being applied, because none of the other colour classes will then be present.

You can use whatever colour values suit your design - the ones I used are no more than examples and essentially chosen at random for that purpose smile Likewise the selectors - so long as you start .colsch_[X] then the rest of the selector determines which element you want to style for that particular colour scheme. The ones I used are, again, intended only as an example.

Ah, apologies - please ignore the random 'ipsum' text in the background, its not relevant to the images!
Attachment Selection_026.jpg
In reply to Richard Oelmann

Re: Child themes of Boost

by Jamie Tinley -
Sorry to be dense but my course does not have the colors your course shows no matter which drop down I choose. Do you have a website I can visit to see how to set this up?
I put None Blue Green Tan Pink into my Course Custom Field list and selected that teachers can see this. I purged theme cache, then selected each color in turn blue green tan and in each case even after clearing theme cache I still see the same white background. I chose waxed as the appearance and in "other" I chose the various colors I added in the drop down list. What am I missing here? Thanks
In reply to Richard Oelmann

Re: Child themes of Boost

by Jamie Tinley -
waxed layout files

I don't see the courses.php file inside /var/www/html/moodle/theme/waxed/layout so maybe that is my problem. I downloaded the 3.7 version of waxed from gitup the link below:
https://gitlab.com/ro-mdl-themes/moodle-theme_waxed/-/branches

Should I download the courses.php file from the link below and put it into that path location?
https://gitlab.com/ro-mdl-themes/moodle-theme_waxed/blob/master/layout/courses.php#L41-49
In reply to Richard Oelmann

Re: Child themes of Boost

by Jamie Tinley -
ok, I downloaded your file courses.php and added it to /theme/waxed/layout
then I added the case statements you suggested. here is a screenshot. It's not working yet but how would it know what colsch_blue is? where is that located. The RAw SCSS code iin my waxed theme location RAw SCSS online is Colsch_2 so should I rename it to colsch_blue?
.colsch_2 #page, .colsch_2 #region-main {background-color: #78CBFC;}

I just also tried editing the below cases below to say case "2":
$extraclasses[]='colsch_2';  so the 2 would match the SCSS code in the RAW SCSS code area and it did not change the colors of the backgrounds.
I'm at a loss but I"m sure it's easy somehow.

waxed custom code
In reply to Richard Oelmann

Re: Child themes of Boost

by Jamie Tinley -
After re-reading all your posts several times I think this is the key I'm missing:
In your theme, copy the layout file column2.php and rename as courses.php, then adjust the theme config.php to point to that layout file for course and incourse page types and add code as in Waxed

which line of code at config.php do I edit and how do I make it "point" to the layout files (courses.php)
where in courses pages do I type and add code (did you mean online in the theme waxed in the RAW SCSS, if so I did that step arlready)
Thanks!
In reply to Jamie Tinley

Re: Child themes of Boost

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers
Jamie,
I'm sorry, I'm now lost as to what you are doing.
Waxed is complete as it is, other than the css you want to apply and the course setting dropdown.

1. Download Waxed from github as it is and install it - no changes. Make sure Waxed is your selected theme.
2. Create a custom field in your course settings, as a dropdown, with the values None, Blue, Green, Tan, Pink
3. Add the scss to the Raw scss setting in Waxed
.colsch_2 #page, .colsch_2 #region-main {background-color: #78CBFC;}
.colsch_3 #page, .colsch_3 #region-main {background-color: #AAFDBC;}
.colsch_4 #page, .colsch_4 #region-main {background-color: #FFCD7F;}
.colsch_5 #page, .colsch_5 #region-main {background-color: [ADD A COLOUR HERE];}
Make sure that is working, before you consider whether you want to add the additional code to change the numeric values to text in the css (eg colsch_blue). The additional code (the switch/case) is not necessary, it only makes the css a bit more readable, but if you are fine with the 1,2,3 then don't bother with it. It is entirely optional.

Richard
In reply to Richard Oelmann

Re: Child themes of Boost

by Jamie Tinley -
2019 settingsRaw SCSSColor ChoicesThanks Richard,

I had adaptable as my main theme for Moodle and Waxed as the chosen theme for the course.  I now removed the course.php I had added to layout. But still when I choose a color from the dropdown it does not change. Am I creating the list of colors in the dropdown in the right place?
Besides adding a few more colors I can't see why it does not work. I turned on developer errors and purged cache but don't see why it's not changing the background color when I select it in the course settings page. (I select the waxed theme for appearance and at the bottom in 'other' I choose the color I want.)

Was there supposed to be a courses.php file inside /var/www/html/moodle/theme/waxed/preset  ?
What did you mean by edit config.php to point to the courses.php (where you suggested I edit the column2.php)

In reply to Richard Oelmann

Re: Child themes of Boost

by Jamie Tinley -
HI Richard, do you think the adaptable theme is interfering with waxed normal workings? I pasted screenshots of all my setups to see if that helps you help me.
Thanks smile Jamie
In reply to Jamie Tinley

Re: Child themes of Boost

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers
No, no courses.php inside presets, no need to edit config.php - please ignore the early parts of teh thread before I'd added the code into Waxed anyway. Simply use Waxed as it is, no changes.

No, they're separate.

The only other thing I can think of is what have you called the dropdown in the course settings? It needs to match what is in the Waxed code ie must have a shortname 'colourscheme' - and I just had a thought that maybe you may not have spotted my UK spelling of 'colour'.
if ($DB->record_exists('customfield_field', array('shortname' => 'colourscheme'))) {

In reply to Richard Oelmann

Re: Child themes of Boost

by Jamie Tinley -
I did not have it named as colourscheme but now did name it that way but still no change occurs. Why does it sometimes say when I choose say blue 'this value already used' ? Can you only use one colour for the site and no two courses can have the same colour? I'm still wondering if the redirect to colourscheme is going to adaptable. What file is the if statement about colourscheme located in so I can better understand the process? Thanks, I"m sure once I find the cause I'll think it was obvious but it's not obvious now.
In reply to Richard Oelmann

Re: Child themes of Boost

by Jamie Tinley -
Hi Richard,

I uninstalled waxed and re-installed it from the git repository here. I added colourscheme as the shortname of the custom course drop down field. Still I'm failing somehow.

1. why do I get this error below? can more than one course use the same color scheme?
in use
2. I did a subfolder search both in linux and windows for the words scheme, colourscheme, customfield_field  and could not find it anywhere in waxed.
Where is this line below located?

if ($DB->record_exists('customfield_field', array('shortname' => 'colourscheme')))

3. could adaptable still be interfering or perhaps some old themes I uninstalled - references may still be there in my database. Could those affect it?

Thanks Richard, I'm sure I'm doing something stupid on my end I just can't figure out what it is yet.


In reply to Jamie Tinley

Re: Child themes of Boost

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers
https://gitlab.com/ro-mdl-themes/moodle-theme_waxed/blob/master/layout/courses.php#L41-49

Course custom field: *important settings
Name - Colour Scheme
Shortname - colourscheme *
Description - Select optional tweaks to the theme scheme for this specific course.
Required - No *
Unique - No * (From what you've said above, you may have this set to Yes ?)
Menu options (one per line) * -
none
blue
green
pink
tan
Default value - None *
Locked - No *
Visible to - Everyone

No, this code would not be affected by any other theme

AH! - You're using the stable branch! Please use the Master branch for this. As its development for you, its not in the STABLE branch as yet. That's the problem, you don't actually have the code I've been assuming you've got smile
In reply to Richard Oelmann

Re: Child themes of Boost

by Jamie Tinley -
Hooray!!!!!!!!!!!! Thank you SO much for helping me Richard! That was it, the master one works and I could find those key words in the files when I searched! And taking off unique worked too!
Thank you so much, I'm so very very very sorry to ask you SO many questions - I wish I saw that earlier - such an easy fix!
For anyone following this thread, use the master branch of waxed Waxed works, not 3.7 stable.
In reply to Richard Oelmann

Re: Child themes of Boost

by Jamie Tinley -

Thanks Richard I will try it with waxed then if I fail 3 weeks is nothing compared to the last 15 years of struggling to best serve my users. Thanks

In reply to Richard Oelmann

Re: Child themes of Boost

by Jamie Tinley -
HI Richard, thanks! Sorry finally back home near a real computer (not my phone) and trying to install waxed for 3.7 and I'm getting a validation error below. I tried both by downloading the zip file and also the online install button with same results. I made sure to chmod -R 0777 my theme directory so that's not it. Ideas? Thanks,
Jamie
Validating theme_waxed ... Error
[Error] Extracted file not found [{"file":"waxed\/classes\/output\/core\/"}]
Installation aborted due to validation failure

Headsup:  this validation error was only from the moodle community plugin site so I searched and found your git site is more up to date and it worked just now from there.  (url below for those with same issue). 

also note if you use the admin theme list and have adaptable then it lists it as another adaptable theme instead of waxed. ie, I have installed choices of 
Adaptable
Boost
Classic (that worked btw Richard for re-installing it smile
Fordson
waxed
and put in theme list Boost, waxed and the result was 
adaptable
adaptable
???
In reply to Jamie Tinley

Re: Child themes of Boost

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers
Thanks Jamie - I'll update the database asap
I don't have adaptable installed on my dev laptop, and its strange that from what you've put, both Boost and Waxed appear as Adaptable...
There's no Adaptable code in Waxed, and definitely no language strings to suggest this issue.