SVG Kirbtag plugin

Because SVG is simple goodness, and because we needed it when creating our website, here’s a kirbytag that lets you inline SVG images

Kirby SVG kirbytag

Version

A kirbytext extension to inline svg images for Kirby.

Installation

1. Kirby CLI

If you are using the Kirby CLI you can install this plugin by running the following command in your shell from the root folder of your Kirby installation:

kirby plugin:install Thiousi/kirby-svg-kirbytag

2. Manual

Download this archive, extract it and rename it to svg-kirbytag. Copy the folder to your site/plugins folder.

3. Git Submodule

If you know your way around git, you can download this as a submodule:

$ git submodule add https://github.com/Thiousi/kirby-svg-kirbytag site/plugins/svg-kirbytag

Usage

This kirbytag uses a stripped down version of the image tag as its base. Therefore, it works in a similar fashion but can’t accept as many options. Here is the full list:

kirbytext::$tags['svg'] = array(
  'attr' => array(
    'class',
    'caption',
    'link',
    'linkclass',
    'title',
    'target',
    'rel',
  ),

class

Class added to the figure wrapping the svg tag. The figure appears if a caption is set or if the otion kirbytext.image.figure is set to true in the configuration fo the site.

caption

Adds a figcaption tag inside the figure containing the svg

link, linkclass, title, target, rel

Constructs a link that wraps the svg:

<a href="link" class="linkclass" title="title" target="target" rel="rel">

Credits

This plugin was created as part of writing up a tutorial on macotuts: website link no longer available (edited by @texnixe).

License

MIT

7 Likes

So svg files doesn’t work with the image tag?

This “reads” an svg image to print it’s content directly in the html. It’s particularly neat for small SVGs (think icons) as it permits one less call to the server.

1 Like

This is great and works great, when you just put the svg.php in default kirby tags folder WITHOUT adding the supplied plugin file

I guess

$kirby->set('tag', 'svg', __DIR__ . DS . 'tags');

doesn’t work anymore in current release

@scsskid Did that ever work? The registry set method for tags hasn’t changed since it was introduced.

I just discovered this “plugin” yesterday and just couln’t get it to work at first. I get what the author wanted to achieve, but my PHP and Kirby knowledge is limited, furthermore I guess it’s quite unnessecary to pack this in a plugin

thanks anyways @Thiousi

To make this work in the plugin-folder use:

// kirby-tag.php
$filePath = __DIR__ . DS . 'tags' . DS . 'svg.php';
include( $filePath );