|linenumbers Filter

prepends each line of text with a line number.

String As Markdown

Argument
None

Documentation

Prepends each line of text with a line number.

Variable

shopping_list = '''Carrots
Honey
Milk
Butter'''

Template

{{ shopping_list|linenumbers }}

Result

1. Carrots
2. Honey
3. Milk
4. Butter

In a browser, whitespace is condensed, so the output would be:

1. Carrots 2. Honey 3. Milk 4. Butter

Commentary

Useful for plain text, but not typically for HTML.

More String Filters

All String Filters


Did we get something wrong? Is there a use case for the linenumbers filter that we should add? Please let us know.

Send Feedback

Official Documentation
This page last updated on August 2, 2026