Moodle App Remote Themes: Difference between revisions
- Moodle App Overview
- Moodle App Development Guide
- Moodle App Plugins Development Guide
- Moodle App Remote Themes
- Moodle App Customisation
- Setting up your development environment
- Using the Moodle App in a browser
- Moodle App Translation
- Moodle App FAQ
- Moodle App Development Process
- Moodle App Release Notes
Upgrade from previous versions:
- See all Moodle App pages
- See pages for Moodle App Ionic 5 (current)
- See pages for Moodle App Ionic 3 (legacy)
- See pages Moodle App Ionic 1 (legacy)
- See pages for Moodle App Phonegap (legacy)
For user documentation see Moodle Mobile
m (Noeldemartin moved page Moodle Mobile Themes to Moodle App Remote Themes: Consistency) |
(Update after 3.9.5 release) |
||
Line 1: | Line 1: | ||
{{Moodle App (Ionic 5)}} | {{Moodle App (Ionic 5)}} | ||
== How do Remote Themes work? == | |||
When you enter a site, it downloads any file configured on the <code>mobilecssurl</code> administration field and injects the styles in the app. Every time you change between sites, each style will be enabled or disabled appropriately. | |||
The styles will remain enabled in the login page, but any other page that is not related with a specific site will use the default styles. For example, pages to add or remove sites cannot be customized with Remote Themes. | |||
== How can you create your own theme? == | |||
First of all, Remote Themes are only available for sites that purchased a Premium subscription for the Moodle App. You can check the different plans in [https://apps.moodle.com the Apps Portal]. If you want, you can follow the instructions in this document without purchasing a subscription and it will work in your development environment. | |||
In order to create your own theme, we recommend that you use the app from [https://master.apps.moodledemo.net master.apps.moodledemo.net] and check the styles using the browser inspector. You can use any Chromium-based browser, but you should launch it with some special arguments. You can read more about that in the [[Using the Moodle App in a browser]] page. If you need to test a different version of the app, you can also use [https://integration.apps.moodledemo.net integration.apps.moodledemo.net] for the latest development version or [[Moodle App Docker Images|the Docker images]] for anything more specific. | |||
Once you have everything ready, you can configure your theme by going to "Site administration > Mobile app > Mobile appearance" in your site and setting the <code>mobilecssurl</code> field to a url pointing to a CSS file. This file can be placed inside your Moodle installation in your custom theme, inside a local plugin, or hosted elsewhere. | |||
You can get started with the following example, and you should see the background of the top bar change to red once you log into the app: | |||
<syntaxhighlight lang="css"> | |||
body { | |||
--core-header-toolbar-background: red; | |||
} | |||
</syntaxhighlight> | |||
=== Applying theme changes during development === | |||
For performance reasons, the app caches the styles after you log in for the first time. So if you make any changes, you won't see them unless you log out and log in again. However, there is a faster way to update them. You can also open the Preferences page in the app and click on the "Synchronise now" button. This will download the files again, and you can use this method to iterate on your styles while you make the theme. | |||
The file can also be cached by the browser, so when you do this make sure to [https://developer.chrome.com/docs/devtools/network/reference/#disable-cache disable network cache] as well. | |||
=== | === Knowing what to style === | ||
Depending on how much you want to customize the UI, you'll need to do different things. | |||
You can | The application defines some [https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties CSS properties] that can help you customize basic styles, like the one we used in our example above to change the background color of the header toolbar. You can find these variables in the source code, the main ones are defined within [https://github.com/moodlehq/moodleapp/blob/master/src/theme/theme.light.scss theme.light.scss] and [https://github.com/moodlehq/moodleapp/blob/master/src/theme/theme.dark.scss theme.dark.scss], and you can find others within component styles. | ||
If you need anything more specific, the application is built using [https://ionicframework.com/docs/theming/basics the Ionic Framework], so reading their documentation can help you understand how the UI works and which components are available. We have some custom components that you won't find listed on their documentation, but most of them built on top of Ionic's. | |||
Finally, if you need to style something even more specific, you can always [https://github.com/moodlehq/moodleapp browse the source code] to see how a specific page is built. You can also use the [Elements Panel](https://developer.chrome.com/docs/devtools/dom/) of your browser to inspect styles and debug anything that isn't working as you'd expect. Depending what you are trying to do, remember that this is only a development environment and it may not work correctly in a native device. If you are doing anything complicated, make sure to double check using a real device to see that everything looks good. | |||
=== Showing course summary image on course page === | |||
By default, course summary images are hidden to reduce scrolling when entering a course. If you want to change this behaviour, you can include the following CSS in your Remote Theme: | |||
<syntaxhighlight lang="css"> | |||
ion-app core-course-format .core-format-progress-list .core-course-thumb { | |||
display: block !important; | |||
} | |||
</syntaxhighlight> | |||
Notice how we needed to use <code>!important</code> in this case. That's something you'll see often if you override component styles, because the default styles are usually scoped to the Angular component and you won't be able to provide more [https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity specificity] in your selector. | |||
=== Using styles based on app and site versions === | |||
The body element contains classes that indicate the version of the app and the Moodle site, so you can restrict CSS rules to a specific version by prepending one of these classes to the selector. | |||
For example, when accessing a 3.11.2 site using the 3.9.5 app the following classes will be present in the body: | |||
* <code>version-3</code> | |||
* <code>version-3-11</code> | |||
* <code>version-3-11-2</code> | |||
* <code>moodleapp-3</code> | |||
* <code>moodleapp-3-9</code> | |||
* <code>moodleapp-3-9-5</code> | |||
=== Supporting older versions of the app === | |||
=== | |||
If you need to support different versions of the app, or you're upgrading your theme from an older version, you should read the [[Ionic5 style migration guide]]. | |||
== Updating your theme after release == | |||
Once you have configured your theme, some users may already have downloaded previous styles and they will be cached. | |||
If you are updating the styles and you want users to get the latest version, you can change the url of the theme file. This doesn't mean that you need to change the name of the file itself, you can just add some query parameters that will be irrelevant when the file is downloaded: | |||
<syntaxhighlight lang="txt">https://mysite.com/mobile/mobiletheme.css?version=1</syntaxhighlight> | |||
Every time you make some changes in your theme and you want the file to be re-downloaded in the app, just increase this number. | |||
== Difference between Remote Themes and Branded Apps == | |||
Remote Theme styles can be tricky to modify. There are lots of CSS rules and some of them can change between versions. Using your own Branded App, you will have better integrations because you can also use Sass variables to change colors and styles. Additionally, you will get your custom application icon and the theming will cover the entire application, not just pages using your site. | |||
Remote | |||
You can | You can find more info on the [https://moodle.com/branded-app Branded Apps] page. |
Revision as of 10:53, 7 September 2021
How do Remote Themes work?
When you enter a site, it downloads any file configured on the mobilecssurl
administration field and injects the styles in the app. Every time you change between sites, each style will be enabled or disabled appropriately.
The styles will remain enabled in the login page, but any other page that is not related with a specific site will use the default styles. For example, pages to add or remove sites cannot be customized with Remote Themes.
How can you create your own theme?
First of all, Remote Themes are only available for sites that purchased a Premium subscription for the Moodle App. You can check the different plans in the Apps Portal. If you want, you can follow the instructions in this document without purchasing a subscription and it will work in your development environment.
In order to create your own theme, we recommend that you use the app from master.apps.moodledemo.net and check the styles using the browser inspector. You can use any Chromium-based browser, but you should launch it with some special arguments. You can read more about that in the Using the Moodle App in a browser page. If you need to test a different version of the app, you can also use integration.apps.moodledemo.net for the latest development version or the Docker images for anything more specific.
Once you have everything ready, you can configure your theme by going to "Site administration > Mobile app > Mobile appearance" in your site and setting the mobilecssurl
field to a url pointing to a CSS file. This file can be placed inside your Moodle installation in your custom theme, inside a local plugin, or hosted elsewhere.
You can get started with the following example, and you should see the background of the top bar change to red once you log into the app:
body {
--core-header-toolbar-background: red;
}
Applying theme changes during development
For performance reasons, the app caches the styles after you log in for the first time. So if you make any changes, you won't see them unless you log out and log in again. However, there is a faster way to update them. You can also open the Preferences page in the app and click on the "Synchronise now" button. This will download the files again, and you can use this method to iterate on your styles while you make the theme.
The file can also be cached by the browser, so when you do this make sure to disable network cache as well.
Knowing what to style
Depending on how much you want to customize the UI, you'll need to do different things.
The application defines some CSS properties that can help you customize basic styles, like the one we used in our example above to change the background color of the header toolbar. You can find these variables in the source code, the main ones are defined within theme.light.scss and theme.dark.scss, and you can find others within component styles.
If you need anything more specific, the application is built using the Ionic Framework, so reading their documentation can help you understand how the UI works and which components are available. We have some custom components that you won't find listed on their documentation, but most of them built on top of Ionic's.
Finally, if you need to style something even more specific, you can always browse the source code to see how a specific page is built. You can also use the [Elements Panel](https://developer.chrome.com/docs/devtools/dom/) of your browser to inspect styles and debug anything that isn't working as you'd expect. Depending what you are trying to do, remember that this is only a development environment and it may not work correctly in a native device. If you are doing anything complicated, make sure to double check using a real device to see that everything looks good.
Showing course summary image on course page
By default, course summary images are hidden to reduce scrolling when entering a course. If you want to change this behaviour, you can include the following CSS in your Remote Theme:
ion-app core-course-format .core-format-progress-list .core-course-thumb {
display: block !important;
}
Notice how we needed to use !important
in this case. That's something you'll see often if you override component styles, because the default styles are usually scoped to the Angular component and you won't be able to provide more specificity in your selector.
Using styles based on app and site versions
The body element contains classes that indicate the version of the app and the Moodle site, so you can restrict CSS rules to a specific version by prepending one of these classes to the selector.
For example, when accessing a 3.11.2 site using the 3.9.5 app the following classes will be present in the body:
version-3
version-3-11
version-3-11-2
moodleapp-3
moodleapp-3-9
moodleapp-3-9-5
Supporting older versions of the app
If you need to support different versions of the app, or you're upgrading your theme from an older version, you should read the Ionic5 style migration guide.
Updating your theme after release
Once you have configured your theme, some users may already have downloaded previous styles and they will be cached.
If you are updating the styles and you want users to get the latest version, you can change the url of the theme file. This doesn't mean that you need to change the name of the file itself, you can just add some query parameters that will be irrelevant when the file is downloaded:
https://mysite.com/mobile/mobiletheme.css?version=1
Every time you make some changes in your theme and you want the file to be re-downloaded in the app, just increase this number.
Difference between Remote Themes and Branded Apps
Remote Theme styles can be tricky to modify. There are lots of CSS rules and some of them can change between versions. Using your own Branded App, you will have better integrations because you can also use Sass variables to change colors and styles. Additionally, you will get your custom application icon and the theming will cover the entire application, not just pages using your site.
You can find more info on the Branded Apps page.