linenumbers Filter

String

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.


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 April 14, 2020, 9:49 a.m. EST