yii2-fontawesome-inline
thoulah/yii2-fontawesome-inline
inline
/ˈɪnlʌɪn/
adjective
included as part of the main text on a page, rather than in a separate section
/ˈɪnlʌɪn/
adjective
included as part of the main text on a page, rather than in a separate section
This extension provides simple functions for Yii framework 2.0 applications to add Font Awesome Icons inline without the use of JavaScript.
Options
-
bootstrap
( string = 'bootstrap4' ) Bootstrap namespace to use – Currently the only supported option -
fill
( string = 'currentColor' ) Color of the icon. Set to empty string to disable this attribute -
fixedWidth
( bool = false ) Set totrue
to have fixed width icons -
style
( string = 'solid' ) See Referencing Icons. Usable for Font Awesome Pro -
fallbackIcon
( string = '@vendor/fortawesome/font-awesome/svgs/solid/question-circle.svg' ) Backup icon in case requested icon cannot be found -
fontAwesomeFolder
( string = '@vendor/fortawesome/font-awesome/svgs' ) Path to your Font Awesome installation. Usable for Font Awesome Pro -
prefix
( string = 'svg-inline--fa' ) CSS class basename, requires custom CSS if changed -
registerAssets
( bool = true ) Whether or not to register the Font Awesome assets
ActiveForm Specific Global Options
-
ActiveFormFixedWidth
( bool = true ) Set tofalse
to have variable width icons. OverrulesfixedWidth
-
append
( bool = false ) Whether to prepend or append theinput-group
-
groupSize
( string = 'md' ) Set tosm
for small orlg
for large
Usage as a Class
$icon = new \thoulah\fontawesome\Icon();
echo $icon->show('at');
echo $icon->show('github', ['style' => 'brands', 'fill' => '#003865']);
echo $icon->show('font-awesome', ['class' => 'yourClass', 'style' => 'brands']);
Usage as a Widget
use thoulah\fontawesome\IconWidget4 as IconWidget;
echo IconWidget::widget(['name' => 'at']);
echo IconWidget::widget(['name' => 'github', 'options' => ['style' => 'brands', 'fill' => '#003865']]);
echo IconWidget::widget([
'name' => 'font-awesome',
'options' => [
'class' => 'yourClass',
'style' => 'brands'
],
]);
Usage as a Component
This is the preferred method if you need to override any of the default options throughout your application.
Add the component to your Yii config file:'components' => [
'fontawesome' => [
'class' => thoulah\fontawesome\IconComponent::class,
// 'fontAwesomeFolder' => '@npm/fontawesome-pro/svgs',
// 'style' => 'regular',
]
]
Now you can globally insert an icon:
echo Yii::$app->fontawesome->name('at');
echo Yii::$app->fontawesome->name('github', 'brands')->fill->('#003865');
echo Yii::$app->fontawesome->name('font-awesome', 'brands')->class('yourClass');
Usage from ActiveForm (automatic)
use thoulah\fontawesome\bootstrap4\ActiveForm;
$form = ActiveForm::begin();
echo $form->field($model, 'field1', [
'icon' => 'user',
]);
echo $form->field($model, 'field2', [
'icon' => [
'name' => 'github',
'style' => 'brands',
],
]);
echo $form->field($model, 'field3', [
'icon' => [
'name' => 'github',
'style' => 'brands',
'append' => true,
],
]);
ActiveForm::end();
Usage from ActiveForm (manual)
For$icon
you can use any earlier described usage method.
$form = ActiveForm::begin();
echo $form->field($model, 'field', [
'inputTemplate' => $icon->activeFieldAddon('font-awesome', ['style' => 'brands']),
]);
ActiveForm::end();