Skip to content

TomasVotruba/embedded-svg

Repository files navigation

Embedded Macro for Latte

Example

<h1>
    Publications
    {embeddedSvg 'icons/help.svg'}
</h1>

Result HTML code will look like:

<h1>
    Publications
    <svg xmlns="..." >
        ... content of help.svg file ...
    </svg>
</h1>

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.

This allows to stylize SVG by CSS. It isn't easy with SVG linked as an image <img src="icons/help.svg">.

Installation

Require library:

composer require milo/embedded-svg

Register extension in your config.neon and configure it:

extensions:
    embeddedSvg: Milo\EmbeddedSvg\Extension

embeddedSvg:
    baseDir: %wwwDir%/img

Caveats & Limitations

Because embeddedSvg 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.

Resource for Latte 3

About

Macro for embeding SVG into HTML. Preparing for Latte 3

Resources

License

Stars

Watchers

Forks

Packages

No packages published