Download the PHP package ocubom/twig-svg-extension without Composer
On this page you can find all versions of the php package ocubom/twig-svg-extension. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ocubom/twig-svg-extension
More information about ocubom/twig-svg-extension
Files in ocubom/twig-svg-extension
Package twig-svg-extension
Short Description A custom suite of Twig filters for SVG manipulation
License MIT
Homepage https://github.com/ocubom/twig-svg-extension
Informations about the package twig-svg-extension
Contents
* [About TwigSvgExtension](#about-twigsvgextension) * [Getting Started](#getting-started) * [Installation](#installation) * [Usage](#usage) * [Roadmap](#roadmap) * [Contributing](#contributing) * [Authorship](#authorship) * [License](#license)About TwigSvgExtension
TwigSvgExtension is a custom suite of Twig filters for SVG manipulation.
This suite started as an internal class to inline SVG files into HTML documents. This class used to be embedded into several projects. Over time, each project adapted its version slightly, leading to fragmented development and difficult maintenance. Therefore, the development is unified in this extension which is made public in case it is useful for other projects.
Getting Started
Installation
Just use composer to add the dependency:
Or add the dependency manually:
-
Update
composer.json
file with the lines: - And update the dependencies:
Usage
Just register the Twig extension:
The extension defines several filters and functions.
SVG Extension Core
svg
function
The svg function embeds an SVG defined in an external file into the template.
The path is relative to the search path provided as the first argument when creating the runtime.
The second argument can be used to add some attributes to the root element:
svg
(or svg_symbols
) filter
This filter looks for embedded SVGs and converts each of them into a reference to a symbol.
Warning
The filter must be applied at an HTML document level.
If the filter is used in a fragment, an exception will be generated.
Note
The
svg
function can be used to embed SVG files that will be converted with this filter.
FontAwesome Provider
fa
function
Generates a simple FontAwesome HTML tag:
Will generate:
Warning
The result may be slightly different. The order of the attributes or their values may vary.
fontawesome
filter
This filter looks for FontAwesome tags and replaces them by embedding the corresponding SVG.
Warning
The filter must be applied at HTML document level.
If the filter is used in a fragment, an exception will be generated.
Note
The
fa
function can be used to generate the tags.
Iconify Provider
iconify
filter
This filter looks for Iconify SVG Framework or Web Component and replaces them by embedding the corresponding SVG.
Warning
The filter must be applied at HTML document level.
If the filter is used in a fragment, an exception will be generated.
Roadmap
See the open issues for a full list of proposed features (and known issues).
Contributing
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
- Fork the Project.
- Create your Feature Branch (
git checkout -b feature/your-feature
). - Commit your Changes (
git commit -m 'Add your-feature'
). - Push to the Branch (
git push origin feature/your-feature
). - Open a Pull Request.
Authorship
- Oscar Cubo Medina — https://ocubom.github.io
See also the list of contributors who participated in this project.
License
Distributed under the MIT License. See LICENSE for more information.
All versions of twig-svg-extension with dependencies
ext-dom Version *
ext-libxml Version *
bentools/iterable-functions Version ^2.0
iconify/json-tools Version ^1.0
masterminds/html5 Version ^2.0
ocubom/base-convert Version ^2.0
symfony/deprecation-contracts Version ^2.5|^3.2
symfony/options-resolver Version ^5.4|^6.0|^7.0
twig/twig Version ^2.7|^3.0