- Moodle 3.x Developer's Guide
- Ian Wild
- 173字
- 2021-07-02 21:34:44
Text filters
For more information on text filters, take a look at the Moodle documentation at https://docs.moodle.org/dev/Filters. The idea of a filter is that it can transform Moodle text before it is outputted to the screen. For example, text filters are used to transform the code generated by the chemistry and mathematical symbol editor plugins described in the previous section into the actual symbols displayed to the user, or replace a link to a video with an embedded video player.
It is worth noting that text filters are one of the easiest types of plugin to create. It is also worth noting that text filters can cause a big performance hit if we aren't careful with the way they are implemented. Text filters will process every bit of text displayed on the screen through the format_text() function (see https://docs.moodle.org/dev/Output_functions#format_text.28.29), so it makes sense to implement some form of caching if, for example, your filter is having to access the database or generate an image. We talk more about caching later in this chapter.