PHPackages                             milo/embedded-svg - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. milo/embedded-svg

ActiveLibrary[Templating &amp; Views](/categories/templating)

milo/embedded-svg
=================

Latte macro to embed SVG from file into HTML

v1.4.0(1y ago)8429.5k↓42.9%11MITPHPPHP &gt;=7.1.0

Since May 11Pushed 1y ago1 watchersCompare

[ Source](https://github.com/milo/embedded-svg)[ Packagist](https://packagist.org/packages/milo/embedded-svg)[ RSS](/packages/milo-embedded-svg/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (1)Versions (7)Used By (1)

Example
=======

[](#example)

```

    Publications
    {embeddedSvg 'icons/help.svg',
        class => 'help-icon',
        data-toggle => 'popover',
        data-content => 'This is a list of your publications for last 5 years.'
    }

```

Result HTML code may look like:

```

    Publications

        ... content of help.svg file ...

```

Purpose
=======

[](#purpose)

This is a single purpose helper library with a macro definition for [Latte](https://latte.nette.org/), 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 ``.

Installation
============

[](#installation)

Require library by [Composer](https://getcomposer.org/):

```
composer require milo/embedded-svg

```

Register extension in your `config.neon` and configure it:

```
extensions:
    embeddedSvg: Milo\EmbeddedSvg\Extension

embeddedSvg:
    baseDir: %wwwDir%/img
```

Configuration
=============

[](#configuration)

There are some other optional options:

```
embeddedSvg:
    # change name of the macro
    macroName: svgIcon

    # pretty format SVG content (indent tags)
    prettyOutput: yes

    # default  tag attributes, for example
    defaultAttributes:
        class: embedded
        height: 30px
        width: null

    # callbacks called when SVG loaded from file
    onLoad:
        - [SVGSanitizer, sanitize]

    # bitmask of LIBXML_* flags for DOMDocument::load() method
    libXmlOptions: (integer)
```

You can load the extension more then once. In this case, change macro name by `macroName` option.

Option `defaultAttributes` is a XML attributes list for generated `` tag. These are merged. The precedence is (higher to lower):

- macro tag attributes
- default attributes
- attributes of `` tag loaded from file

If the attribute value is `null`, it is not rendered. You can unset attributes from SVG file in that way.

Callback added into `onLoad` event is called when SVG contents is successfully loaded into DOM. Its signature is:

```
function (DOMDocument $dom, Milo\EmbeddedSvg\MacroSetting $setting) {
    ...
}
```

Caveats &amp; Limitations
=========================

[](#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.

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance44

Moderate activity, may be stable

Popularity39

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 88.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~623 days

Total

5

Last Release

438d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a4c732343c0eba814891adfe91dea1754265ea7a5cbed1232d872cac406ff21e?d=identicon)[milonemilo](/maintainers/milonemilo)

---

Top Contributors

[![milo](https://avatars.githubusercontent.com/u/439140?v=4)](https://github.com/milo "milo (8 commits)")[![redwormik](https://avatars.githubusercontent.com/u/2022545?v=4)](https://github.com/redwormik "redwormik (1 commits)")

---

Tags

nettesvglattemacroembedded

### Embed Badge

![Health badge](/badges/milo-embedded-svg/health.svg)

```
[![Health](https://phpackages.com/badges/milo-embedded-svg/health.svg)](https://phpackages.com/packages/milo-embedded-svg)
```

###  Alternatives

[contributte/latte

Extra contrib to nette/latte

111.5M2](/packages/contributte-latte)[nepada/form-renderer

Latte template based form renderer for Nette forms with full support for Bootstrap 3, 4 &amp; 5.

11251.0k](/packages/nepada-form-renderer)[nextras/forms-rendering

Rendering helpers for Nette Framework Forms.

1698.4k2](/packages/nextras-forms-rendering)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
