https://github.com/loadsys/cakephp-svg-icon
https://github.com/loadsys/cakephp-svg-icon
Last synced: 11 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/loadsys/cakephp-svg-icon
- Owner: loadsys
- License: mit
- Created: 2023-02-21T19:55:51.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-02-11T15:35:02.000Z (almost 2 years ago)
- Last Synced: 2025-02-09T11:04:51.432Z (12 months ago)
- Language: PHP
- Size: 15.6 KB
- Stars: 1
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SvgIcon plugin for CakePHP 5.x

This plugin offers an easy way to display SVG icons, with options to customize and/or cache them. It's packaged as a trait that can be used anywhere in your app, with a helper (using the trait) for convenience and caching.
## Installation
You can install this plugin into your CakePHP application using [composer](https://getcomposer.org).
The recommended way to install composer packages is:
```
composer require loadsys/cakephp-svg-icon
```
## Versions
* Tags `1.x` are for CakePHP v4.x.
* Tags `2.x` are for CakePHP v5.x.
## Configuration
Icons should be added to `config/app_svg_icon.php` - see the example included in `config` directory for the expected format. Any SVG icon should work, such as [heroicons](https://heroicons.com) or [Bootstrap Icons](https://icons.getbootstrap.com).
Icons will be cached using the `default` cache config. This can be changed by supplying a different cache config when loading the helper:
``` php
/*
* src/View/AppView.php
*/
public function initialize(): void
{
$this->loadHelper('SvgIcon.SvgIcon', [
'cacheConfig' => 'svg_icon',
]);
}
```
This example would use the `svg_icon` cache config, which can be set in `config/app/php`:
``` php
/*
* Optional configuration settings for the SvgIcon plugin cache
*/
'svg_icon' => [
'className' => FileEngine::class,
'prefix' => 'svg_icon_',
'path' => CACHE . 'views' . DS,
'duration' => '+1 years',
'url' => env('CACHE_DEFAULT_URL', null),
]
```
## Usage
Configured icons can be displayed by name - here's an example based on the names used in the sample `config/app_svg_icon.php`.
``` php
= $this->SvgIcon->get('heroicon.home') ?>
= $this->SvgIcon->get('bootstrap.bi-house') ?>
```
To change default icon attributes, options can be provided:
``` php
= $this->SvgIcon->get('heroicon.home', [
'class' => 'text-gray-300 h-9 w-9',
'stroke-width' => '2',
]) ?>
```
Note that attribute overrides apply only to the `svg` tag and not it's child `path` tag.