composer require ameotoko/feathericon-bundle
config/bundles.php:
Ameotoko\FeatherIcon\AmeotokoFeatherIconBundle::class => ['all' => true],
{{ feathericon('send') }}
This renders the default Feather icon for "send" with no customization.{{ feathericon('home', {size: 24, color: '#4a6fa5'}) }}
{% macro icon(name, options={}) %}
<span class="icon-wrapper">
{{ feathericon(name, options) }}
</span>
{% endmacro %}
Usage:
{{ _self.icon('search', {size: 18, color: '#666'}) }}
<button type="submit" class="btn">
{{ feathericon('save') }} Save
</button>
<div class="input-group">
<input type="text" class="form-control">
<span class="input-group-text">
{{ feathericon('search', {size: 16, color: '#ccc'}) }}
</span>
</div>
Pass icon data from the controller:
// src/Controller/SomeController.php
public function index(): Response
{
return $this->render('template.html.twig', [
'icon' => 'settings',
'iconOptions' => ['size' => 20, 'color' => '#ff5722'],
]);
}
{{ feathericon(icon, iconOptions) }}
{{ feathericon('edit', {stroke: '#000', 'stroke-width': 2, 'fill': 'none'}) }}
send vs Send). Use lowercase as per FeatherIcons.|raw:
{{ feathericon('icon-name')|raw }}
dump to inspect the icon:
{{ dump(feathericon('icon-name', options)) }}
$icons = new \Feather\Icons();
echo $icons->get('icon-name', ['stroke' => '#000']);
pixelrobin/php-feather is compatible with your PHP version (^7.4 || ^8.0).// src/Twig/Extension/CustomFeatherExtension.php
class CustomFeatherExtension extends \Twig\Extension\AbstractExtension
{
public function getFunctions()
{
return [
new \Twig\TwigFunction('customFeatherIcon', [$this, 'renderCustomIcon']),
];
}
public function renderCustomIcon(string $name, array $options = [])
{
// Custom logic here
return (new \Feather\Icons())->get($name, $options);
}
}
// src/Service/FeatherIconCache.php
class FeatherIconCache
{
private $cache = [];
public function get(string $name, array $options = []): string
{
$key = md5($name . serialize($options));
if (!isset($this->cache[$key])) {
$this->cache[$key] = (new \Feather\Icons())->get($name, $options);
}
return $this->cache[$key];
}
}
How can I help you explore Laravel packages today?