yii2: How to work with font awesome icons?
17,130
Solution 1
It's simple
<?= Html::a('<i class="fa fa-fw fa-user"></i> Sign Up',['site/signup'], ['class' => 'btn btn-black', 'title' => 'Sign Up']) ?>
Solution 2
Following code generate your desired HTML.
<?= Html::a(Html::tag('i', '', ['class' => 'fa fa-fw fa-user']) . ' Sign Up ', ['site/signup'], ['class' => 'btn btn-black', 'title' => 'Sign Up']) ?>
Solution 3
You can also use yii2-icons, see: https://github.com/kartik-v/yii2-icons
At first you have to install the extension:
composer require kartik-v/yii2-icons "@dev"
Then you can display the icons e.g. in the following way:
use kartik\icons\Icon;
...
Icon::show('trash', ['title' => 'delete'])
Icon::show('calendar', ['class'=>'fa-2x'])
You can find more examples on this demopage: http://demos.krajee.com/icons
Author by
Zack
I create mainly Java/Android/Swift/SwiftUI The rest I solve problems as they come
Updated on July 22, 2022Comments
-
Zack almost 2 years
I have this HTML link tag that I need to generate using yii\helpers\Html
<a href="register" class="btn btn-black" title="Sign Up"><i class="fa fa-fw fa-user"></i> Sign Up</a>
I am able to do it using method a() but I do not know how to include the font awesome class. Here is the code that I already have using a() method
<?= Html::a('Sign Up',['site/signup'], ['class' => 'btn btn-black', 'title' => 'Sign Up']) ?>
I am using bootstrap for my CSS. Any help would be appreciated.