PHPackages                             polyweb-cz/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. polyweb-cz/embedded-svg

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

polyweb-cz/embedded-svg
=======================

Latte macro to embed SVG from file into HTML

1.1.1(6y ago)01.7kMITPHPPHP &gt;=7.1.0

Since May 11Pushed 6y agoCompare

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

READMEChangelogDependencies (2)Versions (5)Used By (0)

Example
=======

[](#example)

```

    Publications
    {svg '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 polyweb-cz/embedded-svg

```

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

```
extensions:
    embeddedSvg: PolywebCz\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

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 60% 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 ~265 days

Total

3

Last Release

2398d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/02008953927da413ab3d180b95936c243b88d00ed78840ceefedcc9b028b896f?d=identicon)[polyweb-cz](/maintainers/polyweb-cz)

---

Top Contributors

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

---

Tags

nettesvglattemacroembedded

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/polyweb-cz-embedded-svg/health.svg)](https://phpackages.com/packages/polyweb-cz-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)

PHPackages © 2026

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