Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

  • adding the path to the custom css file in frontend\assets\AppAsset.php
  • replaced the bootstrap-theme.css file under frontend\web\assets\e4f17951\css\
  • modified the frontend\config\main.php according to this tutorial

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.

like image 424
Asma_15 Avatar asked Apr 30 '15 20:04

Asma_15


2 Answers

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'
            ]
        ]
    ]
],
like image 156
topher Avatar answered Oct 07 '22 00:10

topher


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

like image 38
leninhasda Avatar answered Oct 06 '22 23:10

leninhasda