yii2-fontawesome-inline

Font Awesome inline for Yii2

This extension provides simple functions for Yii framework 2.0 applications to add Font Awesome Icons inline without the use of JavaScript.

Options

ActiveForm Specific Global Options

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();

Support

Create an issue →
Packagist Version Packagist Downloads PHP Version License Travis (.com) branch