2017 © Pedro Peláez
 

library latte-svg

Latte macro to embed SVG from file into HTML

image

dada-amater/latte-svg

Latte macro to embed SVG from file into HTML

  • Friday, July 20, 2018
  • by dada-amater
  • Repository
  • 0 Watchers
  • 0 Stars
  • 13 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Example init

<h1>
    Publications
    {svgFallback icon-group}
</h1>

Result HTML code IN IE may look like:, (*1)

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

Example of icon

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

Result HTML code IN IE may look like:, (*2)

<svg class="some-class" aria-hidden="true">
    <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#icon-bin"></use>
</svg>

Result in Chrome, FF, Opera may look like:, (*3)

<svg class="some-class" aria-hidden="true">
    <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/images/svg/icon-group/symbol-defs.svg?v=1531909866#icon-bin"></use>
</svg>

Purpose

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., (*4)

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">., (*5)

Installation

Require library by Composer:, (*6)

composer require dada-amater/latte-svg

Register extension in your config.neon and configure it:, (*7)

extensions:
    latteSvg: DadaAmater\LatteSvg\Extension

latteSvg:
    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., (*8)

The Versions

20/07 2018

dev-master

9999999-dev

Latte macro to embed SVG from file into HTML

  Sources   Download

MIT

The Requires

 

nette latte macro svg embedded

20/07 2018

v1.1.0

1.1.0.0

Latte macro to embed SVG from file into HTML

  Sources   Download

MIT

The Requires

 

nette latte macro svg embedded

20/07 2018

v1.0.0

1.0.0.0

Latte macro to embed SVG from file into HTML

  Sources   Download

MIT

The Requires

 

nette latte macro svg embedded