Skip to content

A Craft CMS plugin that provides a custom field type for storing SVG content directly in the database.

License

Notifications You must be signed in to change notification settings

servdhost/svg-field

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SVG Field Plugin for Craft CMS

A Craft CMS plugin that provides a custom field type for storing SVG content directly in the database.

Who's it for?

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).

Features

  • 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

Installation

Install via composer:

composer require servd/craft-svg-field

Usage

Creating an SVG Field

  1. Go to SettingsFields in your Craft Control Panel
  2. Click New field
  3. Choose SVG Field as the field type
  4. Configure your field settings and save

Using the Field

  1. Upload: Click the upload area or drag and drop an SVG file
  2. Preview: The SVG will display immediately after upload
  3. Manage: Use the Remove or Replace buttons to modify content
  4. Save: Save your entry to store the SVG content in the database

Template Usage

Display SVG content in your Twig templates:

{# Basic usage #}
{{ entry.yourSvgField|raw }}

Technical Details

Storage

  • 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

Browser Support

  • Modern browsers with File API support
  • Drag and drop functionality
  • SVG preview rendering

Security

  • SVG content is validated before storage
  • Only valid SVG XML is accepted
  • Content is properly escaped in admin interface

Requirements

  • Craft CMS 5.0+
  • PHP 8.2+

About

A Craft CMS plugin that provides a custom field type for storing SVG content directly in the database.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages