Asma_15
Asma_15

Reputation: 141

custom bootstrap css for YII2 frontend

how can I use a custom CSS (obtained from a bootstrap HTML template) with yii2 framework frontend? (i'm using Yii advanced template)

things i tried and that didn't work:

EDIT:

following the tutorial , i added this to main-local.php:

'assetManager' => [
    'bundles' => [
        'yii\bootstrap\BootstrapAsset' => [
             'sourcePath' => 'frontend/web',
             'css' => ['css/bootstrap.css', 'css/agency.css']
            ],
        ],
    ],

maybe something wrong with sourcePath?

any help will be much appreciated.

Upvotes: 9

Views: 11106

Answers (2)

leninhasda
leninhasda

Reputation: 1740

you can actually edit the AppAsset.php file

<?php
namespace frontend\assets;
use yii\web\AssetBundle;
/**
 * Main frontend application asset bundle.
 */
class AppAsset extends AssetBundle
{
    public $basePath = '@webroot';
    public $baseUrl = '@web';
    public $css = [
        // add your bootstrap or any other css file path
        // example
        'css/bootstrap.css',
        'css/agency.css',
        'css/site.css',
    ];
    public $js = [
    ];
    public $depends = [
        'yii\web\YiiAsset',
        // 'yii\bootstrap\BootstrapAsset', remove / comment this
        // as you don't want to use default bootstrap
    ];
}

it should solve your issue

Upvotes: 4

topher
topher

Reputation: 14860

You can edit your frontend web config file to point to your custom bootstrap.css. Note that the path is relative.

'assetManager' => [
    'bundles' => [
        'yii\bootstrap\BootstrapAsset' => [
            'css' => [
                'bootstrap.css' => 'path/to/your/bootstrap.css'
            ]
        ]
    ]
],

Upvotes: 12

Related Questions