This package provides a Heroicons integration for Twig.
Use composer:
composer require gumbraise/twig-heroicons
You do not need to do anything more to use the extension.
If you use Twig directly, register the extension before using it:
<?php
use MarcW\Heroicons\Twig\HeroiconsExtension;
use Twig\Environment;
$twig = new Environment(/* ... */);
$twig->addExtension(new HeroiconsExtension());
This extension provides a heroicon
function that outputs the icon SVG.
{# function signature #}
{{ heroicon(icon, style, options) }}
{# the default style is 'solid' #}
{{ heroicon('academic-cap') }}
{# use the 'outline' style #}
{{ heroicon('academic-cap', 'outline') }}
{# use the 'mini' style #}
{{ heroicon('academic-cap', 'mini') }}
{# Add a custom class to the SVG #}
{{ heroicon('academic-cap', 'outline', {
'class': "text-green-200",
}) }}
You can add several options at the same time.
- Class
{{ heroicon(icon, style, { 'class': '...' }) }}
- Stroke
{{ heroicon(icon, style, { 'stroke': '#......' }) }}
- Stroke Width
{{ heroicon(icon, style, { 'stroke-width': '...' }) }}
- Fill
{{ heroicon(icon, style, { 'fill': '#......' }) }}
This library is MIT licensed.