Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/manuelodelain/svg-twig-extension
add inline svg with twig
https://github.com/manuelodelain/svg-twig-extension
Last synced: 21 days ago
JSON representation
add inline svg with twig
- Host: GitHub
- URL: https://github.com/manuelodelain/svg-twig-extension
- Owner: manuelodelain
- License: mit
- Created: 2017-11-13T09:03:41.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-07-06T15:34:31.000Z (12 months ago)
- Last Synced: 2024-05-14T02:21:07.843Z (about 1 month ago)
- Language: PHP
- Size: 7.81 KB
- Stars: 18
- Watchers: 4
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Lists
- awesome-twig - SVG - Add inline svg with Twig$ (Twig / Extensions)
- awesome-twig - SVG - Add inline svg with Twig$ (Twig / Extensions)
README
# Svg Twig extension
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'}) }}
```