manuelodelain/svg-twig-extension

There is no license information available for the latest version (0.1) of this package.

Add inline svg with Twig

0.1 2017-11-13 13:15 UTC

This package is not auto-updated.

Last update: 2024-04-28 03:03:40 UTC


README

Add inline svg with Twig version 2 or 3

Installation

With Composer: composer require manuelodelain/svg-twig-extension

Usage

use manuelodelain\Twig\Extension\SvgExtension;
use Twig\Environment;

$twig = new Environment(...);

$twig->addExtension(new SvgExtension());
{{ svg('img.svg') }}

Will output your svg file inline.

You can omit the extension

{{ svg('img') }}

You can add a global base path:

new SvgExtension('assets/img')

Options

Add or replace attributes with the attr property:

{{ svg('img.svg', {attr: {class: 'inline-svg', id: 'marker-1'}}) }}

Add CSS classes:

{{ svg('img.svg', {classes: 'add-classname another-classname'}) }}