This module adds a simple method to include inline SVGs in twig templates.

To configure:
1. Ensure your combined SVG file is in your default theme /images/ folder - I'd recommend using Gulp to do this. @see

https://www.npmjs.com/package/gulp-cheerio
https://www.npmjs.com/package/gulp-svgstore
https://www.npmjs.com/package/gulp-svgstore#transform-svg-sources-or-com...

2. Optionally, configure svg file paths via /admin/config/twig_svg/config
3. Enable the Twig SVG module
4. To include an SVG icon in a twig template, add the following in the relevant
html.twig file:

{{ icon('icon-name', 'Icon title') }}

Optionally, to add a title, classes, and additional attributes:
{{ icon('icon-name', 'Icon title', ['extra-class', 'another-class'], {'name-one': 'value-one', 'name-two': 'value-two'}) }}

Optionally, to add a title, classes, additional attributes and wrapper classes:
{{ icon('icon-name', 'Icon title', ['extra-class', 'another-class'], {'name-one': 'value-one', 'name-two': 'value-two'}, ['wrapper-class-1', 'wrapper-class-2']) }}

Credit to https://www.lullabot.com/articles/better-svg-sprite-reuse-in-drupal-8 for the fundamentals of this.

Supporting organizations: 
Original idea and blog post
Development time.

Project information

Releases