black-lamp / yii2-file-icons
Widget for getting the font-icon for file extension
Installs: 981
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 1
Type:yii2-extension
Requires
- php: >=5.6.0
- yiisoft/yii2: ^2.0.4
Requires (Dev)
This package is not auto-updated.
Last update: 2025-03-02 04:47:46 UTC
README
Widget for getting the font-icon for file extension
Installation
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.
Using
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.
Widget configuration properties
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!' |
Default icon set
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');