Latte macro to embed SVG from file into HTML

v1.4.0 2019-02-25 15:39 UTC

This package is not auto-updated.

Last update: 2020-10-17 08:30:16 UTC


    {svgFallback icon-group}

Result HTML code IN IE may look like:

    <svg xmlns="..." class="..." ...>
        ... content of symbol-defs.svg file ...

Example of icon

{svg bin, some-class, icon-group}

Result HTML code IN IE may look like:

<svg class="some-class">
    <use xmlns:xlink="" xlink:href="#icon-bin"></use>

Result in Chrome, FF, Opera may look like:

<svg class="some-class">
    <use xmlns:xlink="" xlink:href="/images/svg/icon-group/symbol-defs.svg?v=1531909866#icon-bin"></use>


This is a single purpose helper library with a macro definition for Latte, the PHP templating engine. It loads SVG source file and embed it into HTML code in compile time.

Motivation for this is possibility to stylize SVG by CSS then. It is not (easily) possible with SVG linked as an image like <img src="icons/help.svg">.


Require library by Composer:

composer require dada-amater/latte-svg

Register extension in your config.neon and configure it:

    latteSvg: DadaAmater\LatteSvg\Extension

    baseDir: %wwwDir%
    wwwPathMask: 'images/svg/{group}/symbol-defs.svg'
    defaultGroup: base
    defaultIconClass: svg-icon
    iconNamePrefix: icon

Caveats & Limitations

Because svg is a macro, it is compiled into PHP only once and then is cached. So, when you change the macro configuration, probably in NEON, you have to purge Latte cache.