jmf/twig-icon-bundle

Symfony bundle for rendering pre-set icons in Twig templates.

Maintainers

Package info

github.com/jmfeurprier/twig-icon-bundle

Type:symfony-bundle

pkg:composer/jmf/twig-icon-bundle

Statistics

Installs: 3

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.0 2026-05-30 12:27 UTC

This package is auto-updated.

Last update: 2026-05-30 12:28:03 UTC


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