Download the PHP package slashworks/contao-simple-svg-icons-bundle without Composer
On this page you can find all versions of the php package slashworks/contao-simple-svg-icons-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download slashworks/contao-simple-svg-icons-bundle
More information about slashworks/contao-simple-svg-icons-bundle
Files in slashworks/contao-simple-svg-icons-bundle
Package contao-simple-svg-icons-bundle
Short Description Simply use SVG icons from an SVG icon sprite file with Contao inserttags.
License LGPL-3.0-or-later
Informations about the package contao-simple-svg-icons-bundle
Contao 4 Simple SVG Icons Bundle
About
With this extension you can easily add SVG icons from an icon-sprite file to your website via Contao Inserttags.
It also allows to output inline SVG from an SVG file in the file system.
Installation
Install with .
After updating the database, select the SVG icon sprite file in the settings of your theme. Use the new field icon files to select the SVG icon sprite file. The icons you can use are taken from this file.
For an easy start, download the example-sprite.svg and place it inside the files folder of your contao installation.
An SVG icon sprite file is a collection of multiple SVG icons, defined within a .
The menu icon for example looks like this:
The important part for using this icon is the id of the symbol.
For further information about creating your own SVG icon sprite file you can check out A Guide to Create and Use SVG Sprites.
Usage
SVG Sprite
When you want to output a symbol from an SVG sprite, the base format is
.
The rendered output:
Inline SVG
You can also output an SVG file inline.
Instead of the symbol's id you have to provide the UUID of the SVG file in the file system:
The rendered output:
Parameters
You can pass additional parameters to the insert tag:
class:
This adds the given string as CSS class to the svg element and will be rendered as:
id:
This adds the given string as CSS ID to the svg element and will be rendered as:
width:
The width parameter only works with inline SVG.
If the width property is set without a height property, the extension tries to get the aspect ratio from already existing width/height attributes or the viewBox attribute and sets the height accordingly. You can always overwrite this with CSS.
height:
The height parameter only works with inline SVG.
If the height property is set without a width property, the extension tries to get the aspect ratio from already existing width/height attributes or the viewBox attribute and sets the width accordingly. You can always overwrite this with CSS.
You can use multiple parameters in any combination:
Tips
The main purpose for svg icons is to use them in conjuction with text, e. g. menu burger, contact information, slider ui elements, …. As a starting point for the CSS styling of the svg icons you could use the following definitions:
This will scale the icon according to the font-size of the parent element.
Additionally, the vertical positioning requires some further adjustments for fine tuning. You can try to use vertical-align, relative positioning with some top or bottom values, or make the parent a flex-container and use align-items to properly position the enclosed icon.
Example: Burger Menu
Lets walk through a burger menu example.
We want to use the icon_menu_24px from the example sprite, so our inserttag looks like this:
The HTML code with the inserttag:
After setting the font-size for the button and the width for the svg, it will look like this:
Finally we adjust the vertical alignment of the icon:
When using the recommended CSS from the tips section, the SVG icon will inherit from the button.
Of course you can define a different color for the SVG icon itself:
Backend widget for icon selection
The extension contains a custom backend widget to make the icon selection easy and intuitive.
To use the widget, use the following code as reference.
Example dca file, e. g. tl_content
Example language file
Licensing
This contao module is licensed under the terms of the LGPLv3.
Credits
The icons used in the example sprite have been taken from Google Material Icons.