yii2-fontawesome-inline
Font Awesome icons for Yii 2, no JavaScript
inline/ˈɪnlʌɪn/adjectiveincluded 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
falseSet to
true to have fixed width iconsstyle 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
trueWhether or not to register the Font Awesome assets
ActiveForm Specific Global Options
ActiveFormFixedWidth bool
trueSet to
false to have variable width icons. Overrules fixedWidthappend bool
falseWhether to prepend or append the
input-groupgroupSize string
'md'Set to
sm for small or lg for largeUsage 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();