Community Documentation

Creating filters

Last updated January 17, 2008. Created by arhip on January 16, 2008.
Log in to edit this page.

To create a filter, you can do these steps:

  • Go to Input Formats (/admin/settings/filters), then go to Custom Filter tab (6.x)
  • Click Add Filter tab

Now there should be a form asking some properties. Give this new filter:

  • Name, as an identifier for this filter
  • Description, some sort of description to describe what this filter about and what this filter do. It is used only in Custom Filter administration page.
  • Tips (short), short tips to be shown in the node creation form, below body field.
  • Tips (full), longer tips to be shown in Compose Tips. That is the page when you click more information about formatting options.
  • Cache to determine the node should be cached. When this option is on, filtering will be cached. If you need a filter that must be processed everytime the node loads (e.g. filter that shows current date/time, or filter that generates random numbers), you should turn this option off.

Replacement rules

The just created filter won't do anything. Before our new filter could do any filtering, first we must add one or some replacement rules. To add replacement rules, you can do these steps:

  • Go to Custom Filter
  • Click on the name of our new filter (click on the name, not on edit. Edit is for editing properties of the filter).
  • Click Add Rule.

Now there should be a form. Here you can specify:

  • Name, name for this replacement rule.
  • Pattern, pattern to be found.
  • PHP Code, an option to tell Drupal about the replacement text.
  • Replacement Text.
  • Weight.
  • Description.

Using created filter in Input Format

Nested rule and how it works

Using cache option

About this page

Drupal version
Drupal 5.x, Drupal 6.x

Site Building Guide

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.
nobody click here