Widget for getting the font-icon for file extension
Run command
composer require black-lamp/yii2-file-icons
or add
"black-lamp/yii2-file-icons": "^1.0.0"
to the require section of your composer.json.
Example of using
$widget = \bl\files\icons\FileIconWidget::begin([
'icons' => [
'txt' => [
'icon' => \yii\helpers\Html::tag('i', '', ['class' => 'icon-file-txt'])
],
'groups' => [
[
'extensions' => ['jpg', 'png', 'gif'],
'icon' => \yii\helpers\Html::tag('i', '', ['class' => 'icon-picture'])
],
]
]
]);
echo $widget->getIcon('image.jpg');
$widget->end();
Method FileIconWidget::getIcon()
takes file extension, file name or full path to file and returns
icon for file extension. Icon - method gets from configuration array. If icon not found in configuration array
method returns empty icon. Empty icon value gets from emptyIcon
widget option.
Option | Description | Type | Default |
---|---|---|---|
icons | Array with configuration for file extensions and icons | array | - |
useDefaultIcons | If set true - widget will be user default icons for files |
boolean | false |
emptyIcon | If icon will not be found if icons array or in defaul icons set - value from this property will be returned |
string | 'Icon for this extension not found!' |
If you set widget option useDefaultIcons
in true
- method FileIconWidget::getIcon()
will be returns
default icons for file extensions. Also you can override default icons if you dont't wont to use default icon
for curren file extension.
<i class="file-text"></i>
<i class="file-pdf"></i>
<i class="file-power-point"></i>
<i class="file-archive"></i>
<i class="file-word"></i>
<i class="file-excel"></i>
<i class="file-picture"></i>
<i class="file-video"></i>
<i class="file-code"></i>
or using \bl\files\icons\helpers\IconHelper
IconHelper::icon('text');
IconHelper::icon('pdf');
IconHelper::icon('power-point');
IconHelper::icon('archive');
IconHelper::icon('word');
IconHelper::icon('excel');
IconHelper::icon('picture');
IconHelper::icon('video');
IconHelper::icon('code');