gumbraise/twig-heroicons

Unofficial Twig integration for Heroicons

2.0.18.3 2023-11-06 21:32 UTC

This package is auto-updated.

Last update: 2025-07-07 00:59:39 UTC


README

tests

This package provides a Heroicons integration for Twig.

Install

Use composer:

composer require gumbraise/twig-heroicons

Symfony

You do not need to do anything more to use the extension.

Twig

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());

Usage

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",
}) }}

Supported Options

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': '#......'  
    }) }}

License

This library is MIT licensed.