Skip to content

Commit 2081176

Browse files
authored
Merge pull request #982 from sarjona/themeplugins
[docs] Migrate Themes overview
2 parents 54d7547 + 8893b6f commit 2081176

File tree

8 files changed

+1182
-0
lines changed

8 files changed

+1182
-0
lines changed

data/migratedPages.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,6 +1686,9 @@ Testing_instructions_guide:
16861686
Testing_of_integrated_issues:
16871687
- filePath: "/general/development/process/testing/integrated-issues.md"
16881688
slug: "/general/development/process/testing/integrated-issues"
1689+
Themes_overview:
1690+
- filePath: "/docs/apis/plugintypes/theme/index.md"
1691+
slug: "/docs/apis/plugintypes/theme/"
16891692
Time_API:
16901693
- filePath: "/docs/apis/subsystems/time/index.md"
16911694
slug: "/docs/apis/subsystems/time/"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!-- markdownlint-disable first-line-heading -->
2+
<!-- cspell:ignore choosereadme, configtitle -->
3+
4+
Each plugin must define a set of language strings with, at a minimum, an English translation. These are specified in the plugin's lang/en directory in a file named after the plugin.
5+
6+
Language strings for the plugin. Required strings:
7+
8+
- **`pluginname`** - name of plugin.
9+
- **`choosereadme`** - descriptive text displayed beneath the theme information dialog screenshot.
10+
- **`configtitle`** - settings text for this type of plugin.
11+
12+
You will usually need to add your own strings for two main purposes:
13+
14+
- Creating suitable form controls for users who are editing the theme settings; and
15+
- Displaying information about the theme.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
$string['pluginname'] = 'Boost';
2+
$string['choosereadme'] = 'Boost is a modern, highly-customisable theme. This theme is intended to be used directly, or as a parent theme when creating new themes utilising Bootstrap 4.';
3+
$string['configtitle'] = 'Boost';

docs/apis/plugintypes/theme/fonts.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
title: Fonts
3+
tags:
4+
- Plugins
5+
- Theme
6+
- Fonts
7+
sidebar_position: 3
8+
---
9+
10+
<Since version="2.6" />
11+
12+
CSS3 standard introduced the possibility to specify custom fonts, see [CSS web fonts tutorial](http://www.w3schools.com/css/css3_fonts.asp).
13+
14+
Moodle includes support for plugin or theme fonts. It is very similar to theme images and pix subdirectories.
15+
16+
## Font file locations
17+
18+
Depending on where you intend to use the font put it into one of the following locations:
19+
20+
- `/lib/fonts/` Fonts used in core.
21+
- `/plugindir/fonts/` Fonts used by plugin.
22+
- `/theme/sometheme/fonts/` Theme specific fonts.
23+
24+
You can also override core and plugin fonts in theme:
25+
26+
- `/theme/sometheme/fonts_core/` Overridden core fonts.
27+
- `/theme/sometheme/fonts_plugins/plugintype_pluginname/` Overridden fonts of some plugin.
28+
29+
:::important
30+
31+
- Subdirectories are not allowed.
32+
- Use only lowercase alphanumeric characters and underscore in font file names.
33+
- WOFF (Web Open Font Format), TTF (True Type Fonts), OTF (OpenType Fonts), SVG (Scalable Vector Graphic) and EOT (Embedded OpenType) fonts are supported, but it's recommended to use WOFF fonts.
34+
35+
:::
36+
37+
### CSS placeholders
38+
39+
```css title="Use a font in a plugin"
40+
@font-face {
41+
font-family: ThreeDumb;
42+
src: url([[font:mod_book|3dumb.woff]]);
43+
}
44+
```
45+
46+
The placeholder references file `/mod/book/fonts/3dumb.woff`, the new font face could be for example used for book headings:
47+
48+
```css
49+
.path-mod-book .book_chapter_title {
50+
font-family: ThreeDumb;
51+
}
52+
```
53+
54+
If you want to use some font in theme only, you can for example:
55+
56+
```css title="Use a font in theme only"
57+
@font-face {
58+
font-family: goodDogFont;
59+
src: url([[font:theme|good_dog.woff]]);
60+
}
61+
62+
a {font-family:goodDogFont;}
63+
```
64+
65+
The font would be stored in `/theme/yourtheme/fonts/good_dog.woff` file.
66+
67+
Based on previous example, if you want to use some font stored in `/lib/fonts/` directory, you have to replace `font:theme` by `font:core`.
68+
69+
### More free fonts
70+
71+
Please respect all licenses for font redistribution, you can get some nice free fonts from [http://www.fontsquirrel.com](http://www.fontsquirrel.com) for example.
72+
73+
:::warning
74+
75+
This is not intended for forcing of something like Comic Sans on all your visitors ;-)
76+
77+
:::

docs/apis/plugintypes/theme/images.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
---
2+
title: Images and icons in themes
3+
tags:
4+
- Plugins
5+
- Theme
6+
- Images
7+
- Icons
8+
sidebar_position: 2
9+
sidebar_label: Images and icons
10+
---
11+
12+
One of the theme features is the ability to override any of the standard images within Moodle when your theme is in use. At this point, let's explore how to utilize your own images within your theme and how to override the images being used by Moodle.
13+
So first up a bit about images within Moodle:
14+
15+
1. Images you want to use within your theme **must** to be located within your theme's `pix` directory.
16+
1. You can use sub directories within the `pix` directory of your theme.
17+
1. Images used by Moodle's core are located within the `pix` directory of Moodle.
18+
1. All plugins should store their images within their own `pix` directory.
19+
20+
The following section assumes that there are two image files in the `pix` directory of a theme named `yourthemename`:
21+
22+
- `/theme/yourthemename/pix/imageone.svg`
23+
- `/theme/yourthemename/pix/subdir/imagetwo.png`
24+
25+
The first image is an SVG, and the second a PNG located in a subdirectory.
26+
27+
## Use images in templates
28+
29+
The following example illustrates how to make use of these images within your layout file so they can be inserted in your layout template.
30+
31+
```php title="theme/yourtheme/layout/somelayout.php"
32+
$templatecontext = [
33+
$imageone => $OUTPUT->pix_url('imageone', 'theme'),
34+
$imagetwo => $OUTPUT->pix_url('subdir/imagetwo', 'theme'),
35+
];
36+
37+
echo $OUTPUT->render_from_template('theme_yourtheme/somelayout', $templatecontext);
38+
```
39+
40+
:::note
41+
42+
A method of Moodle's output library is utilized to generate the URL to the image. It's not too important how that function works, but it is important that it's used, as it's what allows images within Moodle to be overridden.
43+
44+
:::
45+
46+
:::danger Important
47+
48+
**DO NOT** include the image file extension. Moodle will work it out automatically and it will not work if you do include it.
49+
50+
:::
51+
52+
```handlebars title="theme/yourtheme/templates/somelayout.mustache"
53+
<img src="{{{imageone}}}" alt="Please give your image alt text or set the role to presentation" width="50" height="50">
54+
<img src="{{{imagetwo}}}" alt="Please give your image alt text or set the role to presentation" width="50" height="50">
55+
```
56+
57+
## Use images in CSS
58+
59+
The following is how you would use the images from within CSS/SCSS as background images.
60+
61+
```css
62+
.divone {
63+
background-image: url([[pix:theme|imageone]]);
64+
}
65+
66+
.divtwo {
67+
background-image: url([[pix:theme|subdir/imagetwo]]);
68+
}
69+
```
70+
71+
A placeholder is used within the CSS to allow use of a pix icon. During the CSS/SCSS compilation, these placeholders are converted into a URL which the browser can fetch and serve.
72+
73+
:::note
74+
75+
Notice that the image file extension included. The reason for this leads us into the next topic, how to override images.
76+
77+
:::
78+
79+
## Override images
80+
81+
From within a theme you can **very** easily override any standard image within Moodle by simply adding the replacement image to the theme's pix directory in the same sub directory structure as it is in Moodle.
82+
So, for instance, if there is a need to override the following images:
83+
84+
1. `/pix/moodlelogo.png`
85+
1. `/pix/i/user.svg`
86+
1. `/mod/chat/pix/monologo.svg`
87+
88+
Simply add the replacement images to the theme in the following locations:
89+
90+
1. `/theme/themename/pix_core/moodlelogo.png`
91+
1. `/theme/themename/pix_core/i/user.svg`
92+
1. `/theme/themename/pix_plugins/mod/chat/monologo.svg`
93+
94+
:::note
95+
96+
A `pix_core` directory has been created in the theme to store the replacement images. For a specific activity module like chat, the directory `pix_plugins/mod/chat` is needed. This directory is `pix_plugins` and then the plugin type (`mod`) and then the plugin name (`chat`).
97+
98+
:::
99+
100+
Another noteworthy aspect is that Moodle not only searches for replacements of the same image type (svg, png, jpg, gif, and so on) but also replacements in any image format. This is why the image file extension was never specified when working with our images above.
101+
This means that the following would also work:
102+
103+
1. `/theme/themename/pix_core/moodlelogo.svg`
104+
1. `/theme/themename/pix_core/i/user.jpg`
105+
106+
For a more detailed description of how this all works see the page on [Using images in a theme](https://docs.moodle.org/dev/Using_images_in_a_theme).

0 commit comments

Comments
 (0)