gumbraise / twig-heroicons
Unofficial Twig integration for Heroicons
Installs: 1 223
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 4
pkg:composer/gumbraise/twig-heroicons
Requires
- twig/twig: ^2.12|^3.0
Requires (Dev)
- phpunit/phpunit: ^9.6.10
- symfony/framework-bundle: ^5.0
README
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.