Download the PHP package clubstudioltd/craft-inline-svg without Composer
On this page you can find all versions of the php package clubstudioltd/craft-inline-svg. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download clubstudioltd/craft-inline-svg
More information about clubstudioltd/craft-inline-svg
Files in clubstudioltd/craft-inline-svg
Package craft-inline-svg
Short Description A plugin to aid inlining SVGs
License MIT
Informations about the package craft-inline-svg
Craft CMS Inline SVG
A Twig extension for Craft CMS that helps you inline SVGs in your templates.
Why?
While Craft provides an svg()
function out of the box, you need to pass an Asset element or full path every time you use it. If all of your SVGs are stored in the same (or a handful of) directories, this plugin allows you to use shorter, more convenient syntax to inline your SVG.
Installation
Install via the Plugin Store within your Craft 3 installation or using Composer:
Configuration
The plugin comes with a config.php
file that defines some sensible defaults.
If you want to set your own values you should create a inlinesvg.php
file in your Craft /config
directory. The contents of this file will get merged with the plugin defaults, so you only need to specify values for the settings you want to override.
Example Config
You should add the paths to all of the directories where your SVG files are stored to the paths
configuration array.
If you'd like to add a class to every SVG that is output you should add it to the class
configuration value. Separate multiple classes with spaces.
Basic Usage
Once activated and configured you can use the inlineSvg()
function in your templates.
In this example the plugin will look for a file called icon.svg
in all of the configured paths and return the first match it finds.
Adding additional classes
The plugin will add any classes defined in your configuration file to the SVG output. You can add more by passing them as a second parameter:
You can override the classes defined in your configuration file ad hoc using the class
key:
this would output <svg class="override-class" ... >
regardless of any other classes defined in your config file.
Adding additional parameters
You can add additional parameters by passing them as an array:
which would output:
Sanitising & Namespacing
As the inlineSvg()
helper uses the native Craft svg()
helper under the hood, you can still make use of the sanitising and namespacing it offers:
Credits
Inspired by blade-svg