Note: You are currently viewing documentation for Moodle 2.0. Up-to-date documentation for the latest stable version is available here: Filters.

Filters

From MoodleDocs

Filters allow for the for the automatic transformation of entered text into different, often more complex forms. For example the titles of Resources can automatically become hyperlinks that take you to the relevant resource, URLs pointing to mp3 files can become Flash controls embedded in the webpage that let you pause and rewind the audio. The possibilities are endless and there are a number of standard filters included with Moodle and many more specialized filters contributed by the community.

Filters may be added or removed simply by using a file manager to add or remove them to the /filters directory. Moodle detects those that are present and makes them available to use.

Filters administration screen

The filters administration screen enables individual filters to be shown (enabled) or hidden (disabled). Only enabled filters will be applied to displayed text. The order in which filters are applied to displayed text can be significant - you can change the order in which enabled filters are applied using the up and down buttons. The enabled filters are applied from the top of the list down. Some filters have their own settings screen, see the documentation for the individual filter for information.

Cache Controls

  • Text cache lifetime

To reduce load on the server and to speed display of pages, Moodle can store previously processed pages (that have not changed) for a period of time. This setting controls the time for which processed pages are stored. A longer setting may improve performance but has the effect that changes to pages may not become visible for a time. You can switch caching off completely here.

  • Filter uploaded files

This setting enables uploaded files (HTML and text only) to be processed by the filters system. You can choose to have none, only HTML or all files filtered.

  • Filter match once per page

This setting effects the activity and resource linking filters. If set to yes, only the first match on the complete page will be converted to a link. All others will be ignored.

  • Filter match once per text

This setting effects the activity and resource linking filters. If set to yes, only the first match in a discrete block of text will be converted to a link. All others in that text block will be ignored.

  • Filter all strings

When set to yes, all Moodle text will be filtered. This is probably only necessary when using the multi-language filter.

Algebra

This filter will convert algebra code into GIF images. It requires the tex filter to be installed (see below).

Glossary auto-linking

As the name suggests, this filter enables automatic linking of glossary entries. In addition to this filter, individual glossary entries should have the "This entry should be automatically linked" box checked.

It's possible to fine-tune text filtering by adding the following lines from config-dist.php to config.php and removing the //.

// Enabling this will make most text-based filters only match the first time
// a phrase occurs in a given text.  Otherwise all are matched.
//      $CFG->filtermatchonepertext = true;

Multimedia plugins

The Multimedia plugins filter looks for links to various media and replaces them with a proper plugin.

Multi-language content

This filter enables resources to be created in multiple languages. It looks for <lang> tags which indicate that a text contains multiple languages. Then it selects and outputs the best language for the current user. The language of the resource will change when the user changes their selected Moodle language.

To use this feature first create your contents in multiple languages (in the same resource). Then enclose each language block in the following tags:

     <lang lang="XX">your_content_here</lang>
     <lang lang="YY">your_content_in_other_language_here</lang>

TeX notation

The TeX Filter converts TeX code into GIF images. If available it will use the TeX binaries installed on your system. Failing that it uses a binary program called MimeTeX - versions for Linux (glib2.3), Windows and Mac OS X are included in the Moodle distribution. The TeX binaries enable the full range of TeX facilities (available on your server) to be displayed; MineTeX is restricted to an algebraic subset.

Tidy

The tidy filter checks whether HTML code is XHTML compliant, tidying where necessary. To make this filter work you need to have PHP compiled. The discussion Tidy Filter for Moodle 1.5 contains more details.

Word censorship

Template:Moodle 1.6

To enable word censorship in 1.5, Template:Moodle 1.5

  • Activate the word censorship filter
  • Edit config.php in in the root folder
  • Under // 7. OTHER MISCELLANEOUS SETTINGS add the line
$CFG->textfilter1 = 'filter/censor/filter.php';
  • Edit lang/xx/censor.php, adding any words you wish to ban
  • Type some bad words in the HTML editor, as a test. After saving your post, all bad words will be blacked out.

Non-standard filters

  • Jmol - for interactive 3D viewing of molecular structures
  • Code Syntax Highlighting - for more readable excerpts of programming languages including PHP, HTML, CSS, and XML amongst many others

See also