A Craft CMS plugin that provides a custom field type for storing SVG content directly in the database.
It's for folks that need to inline SVG assets efficiently and resiliently, but aren't able to store the SVG files on the local filesystem.
This may be suitable if your site...
- Is load-balanced.
- Is running on ephemeral filesystems, which aren't guaranteed to persist.
- Takes a long time to request SVG files for the purposes of inlining them (e.g. they may be stored in a bucket many miles away).
- Drag & Drop Upload: Intuitive interface for uploading SVG files
- Database Storage: SVG content is stored as text in the database (not as files)
- Live Preview: See uploaded SVGs immediately in the admin interface
- Content Management: Remove or replace SVG content with built-in controls
- Validation: Ensures only valid SVG content is accepted
- Template Ready: Easy integration with Twig templates
Install via composer:
composer require servd/craft-svg-field
- Go to Settings → Fields in your Craft Control Panel
- Click New field
- Choose SVG Field as the field type
- Configure your field settings and save
- Upload: Click the upload area or drag and drop an SVG file
- Preview: The SVG will display immediately after upload
- Manage: Use the Remove or Replace buttons to modify content
- Save: Save your entry to store the SVG content in the database
Display SVG content in your Twig templates:
{# Basic usage #}
{{ entry.yourSvgField|raw }}
- SVG content is stored as text in the database
- No files are created on the server filesystem
- Content is validated as proper XML and SVG format
- Modern browsers with File API support
- Drag and drop functionality
- SVG preview rendering
- SVG content is validated before storage
- Only valid SVG XML is accepted
- Content is properly escaped in admin interface
- Craft CMS 5.0+
- PHP 8.2+