Use heroicons in your Django and Jinja templates.
Project description
Use heroicons in your Django and Jinja templates.
Requirements
Python 3.6 to 3.9 supported.
Django 2.2 to 4.0 supported.
Are your tests slow? Check out my book Speed Up Your Django Tests which covers loads of best practices so you can write faster, more accurate tests.
Usage
The heroicons package supports both Django templates and Jinja templates. Follow the appropriate guide below.
Django templates
Install with python -m pip install heroicons[django].
Add to your INSTALLED_APPS:
INSTALLED_APPS = [ ..., "heroicons", ..., ]
Now in your templates you can load the template library with:
{% load heroicons %}
This provides two tags to render SVG icons: heroicon_outline and heroicon_solid, corresponding to the two icon styles in the set. The tags take these arguments:
name, positional: the name of the icon to use. You can see the icon names on the heroicons.com 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 for outline and 20 for solid.
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
stroke-width
vector-effect
Examples
An outline “academic-cap” icon:
{% heroicon_outline "academic-cap" %}
The same icon, solid, at 40x40 pixels, with some CSS classes:
{% heroicon_outline "academic-cap" size=40 class="h-4 w-4 inline" %}
That icon again, but with the paths changed to a narrower stroke width, and a “data-controller” attribute declared:
{% heroicon_outline "academic-cap" stroke_width=1 data_controller="academia" %}
Jinja templates
Install with python -m pip install heroicons[jinja].
Adjust your Jinja Environment to add the two global functions heroicon_outline and heroicon_solid, imported from heroicons.jinja. For example:
from heroicons.jinja import heroicon_outline, heroicon_solid from jinja2 import Environment env = Environment() env.globals.update( { "heroicon_outline": heroicon_outline, "heroicon_solid": heroicon_solid, } )
Now in your templates you can call those two functions, which render <svg> icons corresponding to the two icon styles in the set. The functions take these arguments:
name, positional: the name of the icon to use. You can see the icon names on the heroicons.com 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 for outline and 20 for solid.
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
stroke-width
vector-effect
Examples
An outline “academic-cap” icon:
{{ heroicon_outline("academic-cap") }}
The same icon, solid, at 40x40 pixels, with some CSS classes:
{{ heroicon_solid("academic-cap", size=40, class="h-4 w-4 inline") %}
That icon again, but with the paths changed to a narrower stroke width, and a “data-controller” attribute declared:
{{ heroicon_outline("academic-cap", stroke_width=1, data_controller="academia") %}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file heroicons-1.2.0.tar.gz
.
File metadata
- Download URL: heroicons-1.2.0.tar.gz
- Upload date:
- Size: 118.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d0fab5dcf952edfc90f0efa1f72d17c711bf9a3a6e82e30990790b2df1329d6e |
|
MD5 | c184d485b20150b95d9a0fc884508729 |
|
BLAKE2b-256 | 3343870e547fa831b1f078a5cb5dfac67007ec99086ca2f08b0be46418a79ee0 |
File details
Details for the file heroicons-1.2.0-py3-none-any.whl
.
File metadata
- Download URL: heroicons-1.2.0-py3-none-any.whl
- Upload date:
- Size: 115.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8558ef86f93e0a08610eb8db12a147c1a4b765e5f265e2ef32ac12745193db91 |
|
MD5 | 53aac3177550dce8b6dd7dbff9b2623e |
|
BLAKE2b-256 | 3a7b57b95ffb9b67fe21fb15345008f3722fff45c6c3f83b0124f14cfcd8c001 |