Skip to main content

Use Tabler Icons in your Django and Jinja templates.

Project description

tablericons

CI pypi black pre-commit

Use Tabler Icons in your Django and Jinja templates.

Requirements

Python from 3.10 supported.

Django from 5.2 supported.

Usage

The tablericons2 package supports both Django templates and Jinja templates. Follow the appropriate guide below.

Django templates

  1. Install with python -m pip install tablericons2[django].

  2. Add to your INSTALLED_APPS:

    INSTALLED_APPS = [
        ...,
        "tablericons",
        ...,
    ]
    
  3. Now your templates can load the template library with:

        {% load tablericons %}
    

Alternatively, make the library available in all templates by adding it to the builtins option:

TEMPLATES = [
    {
        "BACKEND": "django.template.backends.django.DjangoTemplates",
        # ...
        "OPTIONS": {
            # ...
            "builtins": [
                ...,
                "tablericons.templatetags.tablericons",
                ...,
            ],
        },
    }
]

The library provides one tag (icon) to render SVG icons which can take these arguments:

  • name, positional: the name of the icon to use. You can see the icon names on the tabler grid.

  • size, keyword: an integer that will be used for the width and height attributes of the output <svg> tag. Defaults to the icons’ designed sizes, 24. It can also be None, in which case no width or height attributes will be output.

  • Any number of keyword arguments. These will be added as attributes in the output HTML. Underscores in attribute names will be replaced with dashes, allowing you to define e.g. data- attributes.

Most attributes will be added to the <svg> tag containing the icon, but these attributes will be attached to the inner <path> tags instead:

  • stroke-linecap
  • stroke-linejoin
  • vector-effect

Note: unlike the SVG code you can copy from tabler grid, there is no default class.

Examples

An "arrow-down” icon:

    {% icon "outline/arrow-down" %}

The same icon at 40x40 pixels, and a CSS class:

    {% icon "outline/arrow-down" size=40 class="mr-4" %}

That icon again, but with the paths changed to a narrower stroke width, and a "data-controller" attribute declared:

    {% icon "outline/arrow-down" stroke_width=1 data_controller="language" %}

Django Settings

New in 1.1.0

You can override the default size and stroke width using your settings.py:

TABLERICONS_SIZE = 24
TABLERICONS_STROKE_WIDTH = 2

Jinja templates

  1. Install with python -m pip install tablericons[jinja].

  2. Adjust your Jinja Environment to add the global tablericons function from tablericons.jinja. For example:

        from tablericons.jinja import tablericons
        from jinja2 import Environment
    
        env = Environment()
        env.globals.update({
                "tablericons": tablericons
            }
        )
    
  3. Now in your templates you can call that function, which will render the corresponding <svg> icons. The function takes these arguments:

  • name, positional: the name of the icon to use. You can see the icon names on the tabler grid

  • size, keyword: an integer that will be used for the width and height attributes of the output <svg> tag. Defaults to the icons’ designed sizes, 24. Can be None, in which case no width or height attributes will be output.

  • Any number of keyword arguments. These will be added as HTML attributes to the output HTML. Underscores in attribute names will be replaced with dashes, allowing you to define e.g. data- attributes.

Most attributes will be added to the <svg> tag containing the icon, but these attributes will be attached to the inner <path> tags instead:

  • stroke-linecap
  • stroke-linejoin
  • vector-effect

Note: unlike the SVG code you can copy from tabler grid, there is no default class.

Examples

An "outline/arrow-down” icon:

    {{ icon("outline/arrow-down") }}

The same icon at 40x40 pixels and a CSS class:

    {{ icon("outline/arrow-down", size=40, class="mr-4") }}

That icon again, but with the paths changed to a narrower stroke width, and a "data-controller" attribute declared:

    {{ icon("outline/arrow-down", stroke_width=1, data_controller="language") }}

Acknowledgements

This package is forked from franciscobmacedo/lucide which in turn is heavely inspired by Adam Johnson's heroicons.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tablericons2-1.1.0.tar.gz (1.6 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tablericons2-1.1.0-py3-none-any.whl (1.6 MB view details)

Uploaded Python 3

File details

Details for the file tablericons2-1.1.0.tar.gz.

File metadata

  • Download URL: tablericons2-1.1.0.tar.gz
  • Upload date:
  • Size: 1.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for tablericons2-1.1.0.tar.gz
Algorithm Hash digest
SHA256 b84499a4633967339b827b3de2529babeff72252486ee148e421ab04d03db0e7
MD5 12c718832948d51b6e41455b12ef13e0
BLAKE2b-256 fb18c0cbf9d0d99234b6c5615aed8df675c4578dfdfdecb24519164e20ff644c

See more details on using hashes here.

Provenance

The following attestation bundles were made for tablericons2-1.1.0.tar.gz:

Publisher: main.yml on continis/tablericons

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tablericons2-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: tablericons2-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for tablericons2-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 46e556143b1ef2f7a70e3b0ec214aa998e6cbb4d014391043246e33882946736
MD5 33a151c593f40ea01a5c1e3e1d78412a
BLAKE2b-256 57b02294af4976fc85fc0c70dc1895f1b59653b5293340092023d7114453d4a3

See more details on using hashes here.

Provenance

The following attestation bundles were made for tablericons2-1.1.0-py3-none-any.whl:

Publisher: main.yml on continis/tablericons

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page