SvgInline
Inline SVG file manipulation
Overview
Provides simple functions for your Yii3 applications to add SVG files inline and manipulate their properties. It can be extended with Bootstrap Icons and Font Awesome Icons.
echo $svg->file('@vendor/path/icon.svg')->height(42)->title('Yii Rocks');Configuration
Configure SVG inline behavior in config/params.php under the 'yiirocks/svg-inline' key:
fallbackIcon string
'@vendor/yiirocks/svg-inline/src/fallbackIcon.svg'Path to a default SVG file to use when a requested icon is unavailable.
fill string
'currentColor'Default SVG fill color.
iconSets array
[]Array mapping icon set names to their handler classes. Populated automatically when icon set packages (like svg-inline-bootstrap) are installed.
Method Parameters
file string
Required
Valid path to a custom file.
Fluent API
Additional options can be chained onto the file() call:
class string
nullAdditional custom classes.
css array
nullAdditional CSS attributes.
fill string
'currentColor'Color of the icon.
height int
nullThe height of the icon. If height is given without width, the latter will be calculated from the SVG size.
id string
nullId for the SVG tag.
title string
nullSets a title to the SVG output. Defaults to the filename (without extension), capitalized.
width int
nullThe width of the icon. If width is given without height, the latter will be calculated from the SVG size.
Features
Bootstrap Icons
Open-source Bootstrap Icons with clean, consistent aesthetics
Font Awesome Icons
Font Awesome's vast library with thousands of icons and multiple style options
Attribute manipulation
Set ID, classes, fill color, and custom CSS styles on SVG elements
Flexible sizing
Width/height with automatic aspect ratio calculation when only one dimension is specified
Multiple size units
Support for px, em, ex, pt, pc, in, cm, mm, automatically converts to pixels
Fallback icons
Automatically falls back to a default icon if the requested file cannot be found
Immutable fluent API
Method chaining with built-in cloning to prevent unintended mutations