Hi Adam. I would like to have multiple fallbacks for icons that are either user/programatically generated with optional fallbacks where the existance of the icon by name is not always known.
This does what I need and may be of interest to you or your users...(only tested in my case* )
These changes will enable an array to be used as the icon name. The getSVG function loops the array returning the first 'found' icon. if none of the icons are found it returns the config default icon.
{{ svg_icon(['brands/'.$item["brand_icon"],'light/thumbtack','solid/thumbtack'])->class('icon sm') }}
/*
|--------------------------------------------------------------------------
| Fallback Filename (not extension)
|--------------------------------------------------------------------------
|
| If the specified svg file does not exist then it will fallback to this file...
|
*/
'svg_default_name' => 'fallback',
public function svgDefaultName()
{
return $this->config->get('svg_default_name', '');
}
public function getSvg($names)
{
$names = (array) $names;
$names[] = $this->svgDefaultName();
$name = $names[0];
return $this->svgCache->get($name, function () use ( $names) {
foreach($names as $fallback){
$path = sprintf('%s/%s.svg', rtrim($this->svgPath()), str_replace('.', '/', $fallback));
if ($this->files->exists($path))
{
$name = $fallback;
return $this->svgCache[$name] = trim($this->files->get(sprintf('%s/%s.svg', rtrim($this->svgPath()), str_replace('.', '/', $name))));
}
}
});
}