Boost theme: Custom Style per Course

Boost theme: Custom Style per Course

by François Moreau -
Number of replies: 2
Picture of Core developers

So I've been trying to figure out how to go about having different styles for different courses while leveraging the awesome new Boost theme. I'd love to have some insights from the community, especially the third approach. Also, is there any other way to achieve custom styling per course?


The first approach I tried is using a preset with SCSS structured like such:

.course-1 {
.page-header {
...
}
}

.course-5 {
.page-header {
...
}
}
What bothers me with this is:
  • I'll end up with one huge file growing endlessly.
  • I can't seem to figure out how I'm supposed to bundle images with presets.
  • I can't redefine SCSS variables ($bg-color, etc.) per course.

The second approach I tried is making a child theme, putting each ".course-XYZ" section into a separate file, then appending every files' content together through theme_MYTHEME_get_main_scss_content().

  • I can now upload images into MYTHEME/pix and refer to them in the scss files with the [[pix:theme|…]] syntax.
  • A new custom course appearance means simply adding a new SCSS file to a folder.

With this approach, the actual delivered CSS continues to grow with each customized course, although IMHO caring about that would be a case of premature optimization. What really bothers me though is that I still can't redefine variables per course.


The third approach… I'm still trying figure out if this is even feasible and/or overkill. I realize that to redefine SCSS variables per course:

  • the SASS transpiler must run once for each customized course,
  • the result would be one complete transpiled CSS file for each customized course,
  • the theme would need to serve a different CSS file for each customized course.

Right now, the theme stylesheet is served through moodle/theme/styles.php, but this controller doesn't seem cut for that job: it is oblivious to the context and does not accept any argument relating to which stylesheet to serve for a particular theme (it only accepts all). Since that controller deals with a whole lot (transpiling, caching…) I fear that circumventing theme/styles.php  by overloading theme_config::css_urls() is a big deal and kind of ill advised (Is it? Has it been done?).


The fourth approach: I guess I could just build a child theme for every course that needs customizing and enable allowcoursethemes. My main beef with this approach is the amount of boilerplate that we'll go through every time we need to produce some light customizing (color changes + a few background images)… although some scripting might alleviate that.


Average of ratings: Useful (1)
In reply to François Moreau

Re: Boost theme: Custom Style per Course

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

A fifth approach might be to create a new course format (or extend the current ones you use).

That format could include a css setting which could be pulled into the theme scss in the same way that the course summary file is used for course header images.

I'm not sure whether that could be an scss setting and be able to make use of the scss compiling and variables, or whether it would need to be a separate straight css file. It depends on how it gets read and included into the theme.

Note - haven't actually tried this, its just thinking aloud!

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

Re: Boost theme: Custom Style per Course

by François Moreau -
Picture of Core developers

One more reason to get better acquainted to (building my own) course formats! This approach is really nice because the option would be straight into the course. Redefining the SCSS variables would remain off limits for sure though. Since there can be only one transpiled and cached stylesheet per theme and the SCSS variables are globals, you just can't have different values in different contexts.

I've slept on it and I think I'll go with the fourth: one child theme per custom look + allowcoursethemes. Sometimes boring > clever.

(I've been checking out your Boost child themes: great stuff!)