Custom Jinja2 filters?

This works perfect for what I want to do, many thanks:

{%- macro suffix(d) %}
{%- set sfx = {1:'st',2:'nd',3:'rd'} %}
{{- 'th' if 11 <= d <= 13 else sfx.get(d%10, 'th') }}
{%- endmacro %}

{% set day = as_timestamp(states.calendar.waste_collection.attributes.start_time) | timestamp_custom('%A') %}
{% set date = as_timestamp(states.calendar.waste_collection.attributes.start_time) | timestamp_custom('%d') |int %}

{{ day }} {{ date }}{{ suffix(date) }}

The difficulty now is adding it to my value_template of my sensor. How would I add multi line Jinja like the above?.

EDIT: worked it out using the > function :slight_smile:

  waste_collection_date:
    friendly_name: 'Collection Date'
    value_template: >
       {%- macro suffix(d) %}
       {%- set sfx = {1:'st',2:'nd',3:'rd'} %}
       {{- 'th' if 11 <= d <= 13 else sfx.get(d%10, 'th') }}
       {%- endmacro %}
       {% set day = as_timestamp(states.calendar.waste_collection.attributes.start_time) | timestamp_custom('%A') %}
       {% set date = as_timestamp(states.calendar.waste_collection.attributes.start_time) | timestamp_custom('%d') |int %}
       {{ day }} {{ date }}{{ suffix(date) }}
    icon_template: mdi:calendar-star