jmf / twig-icon-bundle
Symfony bundle for rendering pre-set icons in Twig templates.
Package info
github.com/jmfeurprier/twig-icon-bundle
Type:symfony-bundle
pkg:composer/jmf/twig-icon-bundle
1.0.0
2026-05-30 12:27 UTC
Requires
- php: >=8.3
- jmf/template-rendering: ^2.0
- symfony/framework-bundle: ^7.0|^8.0
- twig/twig: ^3.0
- webmozart/assert: ^1.0|^2.0
Requires (Dev)
- overtrue/phplint: ^9
- phpstan/phpstan: ^2
- phpstan/phpstan-strict-rules: ^2
- phpunit/phpunit: ^12|^13
- rector/rector: ^2
- squizlabs/php_codesniffer: ^4
README
Symfony bundle providing a Twig icon() function backed by a configurable icon ID-to-CSS-class mapping.
Requirements
- PHP 8.3+
- Symfony 7.0 or 8.0
Installation
Install with Composer:
composer require jmf/twig-icon-bundle
Register the bundle in config/bundles.php if not using Symfony Flex:
<?php return [ // ... Jmf\Twig\Extension\Icon\JmfTwigIconBundle::class => ['all' => true], ];
Quick Start
Create config/packages/jmf_twig_icon.yaml (example for a usage with Material Symbols):
jmf_twig_icon: mapping: back: 'arrow_back' bookmark: 'check_box_outline_blank' bookmarked: 'check_box' create: 'add' delete: 'delete' download: 'download' link: 'link' print: 'print' read: 'visibility' save: 'save' search: 'search' swap: 'swap_horiz' unlink: 'link_off' update: 'edit' user: 'person' warning: 'warning' zoom_in: 'zoom_in'
Then use in Twig:
{{ icon('back') }}
Configuration Reference
jmf_twig_icon: # Optional prefix before the "icon" function name. Default: '' # Example: 'jmf_' registers 'jmf_icon' instead of 'icon'. prefix: '' # Twig template used to render the icon. Default: '@JmfIcon/material/icon.html.twig' template_path: '@JmfIcon/material/icon.html.twig' # Map of icon IDs to their CSS class names. mapping: back: 'arrow_back' bookmark: 'check_box_outline_blank' bookmarked: 'check_box' create: 'add' delete: 'delete' download: 'download'
A sample configuration file is available in the samples/ directory.
License
MIT