# Add a filter or rendering component

Source: https://zotonic.com/docs/2961/add-a-filter-or-rendering-component

URI: https://zotonic.com/id/2961

Language: en

Use a filter for a small transformation of an input value. Keep missing and unexpected values predictable, and escape output at the point where it becomes HTML.

Use a scomp when rendering needs arguments, context, or more substantial server work. Follow an existing scomp's callback contract and declare caching behavior deliberately.

Place the implementation in the application's `src/filters` or `src/scomps` directory and follow Zotonic naming conventions. Compile and confirm discovery before changing templates to depend on it.

A complete filter example in `src/filters/filter_garden_label.erl`:

```erlang
-module(filter_garden_label).
-export([garden_label/2]).

-spec garden_label(Value, Context) -> binary()
    when Value :: term(), Context :: z:context().
garden_label(<<"open">>, _Context) -> <<"Open to visitors">>;
garden_label(_Value, _Context) -> <<"Check visiting times">>.
```

Compile it and render `{{ "open"|garden_label|escape }}`. Expect “Open to visitors”; a missing value should produce the fallback. These fixed English labels illustrate the callback only: use translation support for real interface labels.

For a scomp, use the current `zotonic_scomp` behaviour and its `render/3` callback, not the old `gen_scomp` behaviour. Start with the source of <a href="/id/1384" class="doc-reference doc-reference-scomp"><code>scomp#button</code></a> for a maintained example that queues browser actions.

License: 

Attribution: 

Related resources: https://zotonic.com/api/agent/related/2961?language=en


## API access

- [API help](<https://zotonic.com/api-help>)
- [OpenAPI specification](<https://zotonic.com/openapi.json>)
- [This resource as JSON](<https://zotonic.com/api/agent/resource/2961?language=en>)
