mblode / svgplaceholder
A plugin which generates an invisible SVG of specific dimensions for use when lazyloading images in Craft CMS templates.
                                    Fund package maintenance!
                                                                            
                                                                                                                                        mblode
                                                                                    
                                                                
Installs: 7 203
Dependents: 1
Suggesters: 0
Security: 0
Stars: 10
Watchers: 0
Forks: 4
Open Issues: 1
Type:craft-plugin
pkg:composer/mblode/svgplaceholder
Requires
- craftcms/cms: ^3.0.0-RC1
 
This package is auto-updated.
Last update: 2025-11-04 01:57:34 UTC
README
A plugin which generates an invisible SVG of specific dimensions for use when lazyloading images in Craft CMS templates.
Requirements
This plugin requires Craft CMS 3.0.0-beta.23 or later.
Installation
To install the plugin, 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 mblode/svgplaceholder - 
In the Control Panel, go to Settings → Plugins and click the “Install” button for svgplaceholder.
 
Usage
{{ craft.svgplaceholder.generate({height:500,width:'300'}) }}
Optionally add a background color with the fill attribute:
{{ craft.svgplaceholder.generate({height:500,width:'300'},'#CCCCCC') }}
Example
When used with Lazysizes and a macro:
_macros/utilities.html
{% macro lazyLoadImage(element, transform) %}
        {% cache using key element.id %}
            <img class="lazyload" src="{{ craft.svgplaceholder.generate({ height: element.height(transform), width: element.width(transform) }) }}" data-src="{{ element.url(transform) }}" alt="{{ element.title }}">
        {% endcache %}
{% endmacro %}
index.html
{% import '_macros/utilities' as utils %}
...
{{ utils.lazyLoadImage(image, 'imageTransformName') }}
Brought to you by Matthew Blode
Based on the Craft CMS 2 plugin: SVG Placeholder