Create a custom filter

Create custom template filters to change the way variables are rendered in your templates. By following some simple rules, Zotonic will automatically find the filter for you:

  1. Create a file in the src/filters/ directory of your site or module.
  2. Prepend the filter filename with filter_.
  3. Export a function with the name of your filter that corresponds to the filename.

So, let’s say you need to sort a list of items and remove duplicate values from it:


uniquesort(List, _Context) ->

The custom uniquesort filter is then available in your templates:

{% for thing in list_of_things|uniquesort %}
    {{ thing }} is now sorted and unique!
{% endfor %}

Create a custom action Other cookbooks Create a custom model

Referred by


Templates are text files marked up using the Zotonic template language. Zotonic interprets that mark-up to dynamically…