gentsagency / craft-inline-icons
A Twig helper for SVG icons.
This package's canonical repository appears to be gone and the package has been frozen as a result.
Installs: 248
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 1
Open Issues: 0
Type:craft-plugin
Requires
- craftcms/cms: ^3.0.0-RC1
This package is not auto-updated.
Last update: 2024-07-07 04:07:56 UTC
README
A Twig helper for SVG icons
Requirements
This module requires Craft CMS 3.0.0-RC1 or later.
Installation
To install the module, follow these instructions.
-
Open your terminal and go to your Craft project:
cd /path/to/project
-
Then tell Composer to load the plugin:
composer require gentsagency/craft-inline-icons
-
Add contents of the
config/app.php
file to yourconfig/app.php
(or just copy it there if it does not exist). This ensures that your module will get loaded for each request. The file might look something like this:return [ 'modules' => [ 'inline-icons' => [ 'class' => \gentsagency\inlineicons\InlineIcons::class, ], ], 'bootstrap' => ['inline-icons'], ];
Overview
The module is intended to work together with @gentsagency/gulp-registry; and more specifically the icons task.
It provides an easy {{ icon('facebook') }}
Twig function to render icons in your Craft templates.
Usage
The examples below assume all front-end assets are built with @gentsagency/gulp-registry to a path within the Craft
@webroot
path.
<ul class="socials"> <li> <a href="https://facebook.com/gentsagency"> {{ icon('facebook') }} </a> </li> <li> <a href="https://instagram.com/gentsagency"> {{ icon( 'instagram', { class: 'inline-icon', inline: true, alt: 'Follow us on Instagram' } ) }} </a> </li> </ul>
Available options
You can pass these options to the Twig function.
class (default: 'icon')
: what class`s should be set on the SVG elementinline (default: false)
: when set to true, the SVG will be parsed by the PHP and embedded in the codealt (default: icon name)
: use this to override the text read by screen readers; set tofalse
to hide the icon from screen readerspath (default: '/assets/icons/icons.svg')
: where the SVG icon spritesheet lives, gets prepended with@webroot
Caveats
When using inline: false
(the default), icons will not show up in Internet Explorer unless you include the svg4everybody polyfill.
Inlined icons will work everywhere and give you some more styling options. Be aware that parsing the SVG in PHP might impact server performance. Use sparingly and with care!