filesizeformat Filter

Number Most Useful

Documentation

Converts a value in bytes to a friendly file size format.

Variable

files = [
    {
        'filename': 'macOS 64-bit installer',
        'filesize': 29163525
    },
    {
        'filename': 'Windows x86-64 executable installer',
        'filesize': 26797616
    },
    {
        'filename': 'Windows x86-64 web-based installer',
        'filesize': 1348896
    }
]

Template

<ol>
  {% for file in files %}
    <li>{{ file.filename }} ({{ file.filesize|filesizeformat }})</li>
  {% endfor %}
</ol>

Result

<ol>
  <li>macOS 64-bit installer (27.8 MB)</li>
  <li>Windows x86-64 executable installer (25.6 MB)</li>
  <li>Windows x86-64 web-based installer (1.3 MB)</li>
</ol>

Commentary

Useful when outputting the file size of a downloadable file.


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

Send Feedback

Official Documentation
This page last updated on Oct. 30, 2022, 1:21 p.m. EST