Yii2 disable Bootstrap Js, JQuery and CSS
In web.php
config file add the following code into components array:
'assetManager' => [
'bundles' => [
'yii\bootstrap\BootstrapPluginAsset' => [
'js'=>[]
],
],
],
To be more comprehensive:
in order to disable Css (bootstrap.css):
'assetManager' => [
'bundles' => [
'yii\bootstrap\BootstrapAsset' => [
'css' => [],
],
],
],
in order to disable JS (bootstrap.js):
'assetManager' => [
'bundles' => [
'yii\bootstrap\BootstrapPluginAsset' => [
'js'=>[]
],
],
],
in order to disable JQuery (jquery.js)
'assetManager' => [
'bundles' => [
'yii\web\JqueryAsset' => [
'js'=>[]
],
],
],
In order to have all of them disabled:
'assetManager' => [
'bundles' => [
'yii\web\JqueryAsset' => [
'js'=>[]
],
'yii\bootstrap\BootstrapPluginAsset' => [
'js'=>[]
],
'yii\bootstrap\BootstrapAsset' => [
'css' => [],
],
],
],
UPDATE
As Soju mentioned in comments, another alternative way would be disabling these files in AppAsset
class, which is located in ./assets/
, then remove the following lines:
public $depends = [
'yii\web\YiiAsset', #REMOVE
'yii\bootstrap\BootstrapAsset', #REMOVE
];
How to disable bootstrap from Yii2 basic?
In web.php
add this code
'assetManager' => [
'bundles' => [
'yii\web\JqueryAsset' => [
'js'=>[]
],
'yii\bootstrap\BootstrapPluginAsset' => [
'js'=>[]
],
'yii\bootstrap\BootstrapAsset' => [
'css' => [],
],
],
],
and remove this line in AppAsset.php
public $depends = [
'yii\web\YiiAsset', #REMOVE
'yii\bootstrap\BootstrapAsset', #REMOVE
];
Efficient way to manage CSS and Javascript in yii2 project
Thanks @Mahsa and @Alex for your replies. I have tried what you suggested but non seemed to work for my use case.
So after more research I decided to use Grunt for my project. I felt that I need a solution which helps me in bifurcating my large CSS and JS files into smaller ones and then using them in layouts as required. This approach is not new, it's something similar how bootstrap manages it's css and js files.
In my project I have 3 different layout each using different as well as same css and js. So i bifurcated my site.css (which originally was more than 14000 lines) to smaller files like buttons.css, layout.css, links.css, table.css, etc.
Then for each layout i created a new Assets file like LayoutOneAssets.php, LayoutTwoAssets.php, etc. These will have only those css or js which are used in the layout or the pages using the layout.
After that with Grunt I created concatenated and minified version of css and js. For Example:
layout.css + links.css + buttons.css => layoutone.css [This is used in LayoutOneAssets.php]
Only drawback of this approach was that I have to write same set of css and js file names in Grunt file and layout assets file also.
Also I disabled default Yii: JqueryAsset, BootstrapAsset. And just added jquery, bootstrap file in grunt common for all.
jquery conflict between 2 versions (using bootstrap template) yii2
After 2 days I finally solved it! It wasn’t jQuery nor Bootstrap. It was my layout.
I wasn’t printing the menu for certain users. Stupid me.
Here’s the code.
<?php
/* @var $this \yii\web\View */
/* @var $content string */
use app\widgets\Alert;
use yii\helpers\Html;
use yii\widgets\Breadcrumbs;
use app\assets\AppAsset;
use app\models\User;
AppAsset::register($this);
?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
<meta charset="<?= Yii::$app->charset ?>">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<?= Html::csrfMetaTags() ?>
<title><?= Html::encode($this->title)?></title>
<?php $this->head() ?>
</head>
<body>
<?php $this->beginBody() ?>
<div class="navbar navbar-inverse">
<div class="container">
<div class="navbar-header">
<!-- Button for smallest screens -->
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></button>
<a class="navbar-brand" href="index.php">
<img src="images/logo.png" alt="Techro HTML5 template"></a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav pull-right mainNav">
<?php if (Yii::$app->user->isGuest) { ?>
<li class="active"><?=Html::a('Inicio', ['index'])?></li>
<li><?=Html::a('Acerca', ['about'])?></li>
<li><?=Html::a('Contacto', ['contact'])?></li>
<li><?=Html::a('Login', ['login'])?></li>
<?php } else if (User::isUserDirector (Yii::$app->user->identity->id)){ ?>
<li class="active"><?=Html::a('Calendario', ['calendario/index'])?></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Área Docente <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><?=Html::a('Profesores', ['profesor/index'])?></li>
<li><?=Html::a('Asignatura', ['asignatura/index'])?></li>
<li><?=Html::a('Cursos', ['curso/index'])?></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Libro de Clases <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><?=Html::a('Alumnos', ['alumno/index'])?></li>
<li><?=Html::a('Notas', ['nota/index'])?></li>
<li><?=Html::a('Apoderados', ['apoderado/index'])?></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Cuenta <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><?=Html::a('Perfil('.Yii::$app->user->identity->username.')', ['site/director'])?></li>
<li><?=Html::a('Cerrar Sesión', ['site/logout'], ['data-method' => 'post'])?></li>
</ul>
</li>
<?php } else if (User::isUserProfesor (Yii::$app->user->identity->id)){?>
<li class="active"><?=Html::a('Calendario', ['calendario/index'])?></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Área Docente <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><?=Html::a('Profesores', ['profesor/index'])?></li>
<li><?=Html::a('Asignatura', ['asignatura/index'])?></li>
<li><?=Html::a('Cursos', ['curso/index'])?></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Libro de Clases <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><?=Html::a('Alumnos', ['alumno/index'])?></li>
<li><?=Html::a('Notas', ['nota/index'])?></li>
<li><?=Html::a('Apoderados', ['apoderado/index'])?></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Cuenta <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><?=Html::a('Perfil('.Yii::$app->user->identity->username.')', ['site/profesor'])?></li>
<li><?=Html::a('Cerrar Sesión', ['site/logout'], ['data-method' => 'post'])?></li>
</ul>
</li>
<?php } else if (User::isUserAlumno (Yii::$app->user->identity->id)){?>
<li class="active"><?=Html::a('Calendario', ['calendario/index'])?></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Área Docente <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><?=Html::a('Profesores', ['profesor/index'])?></li>
<li><?=Html::a('Asignatura', ['asignatura/index'])?></li>
<li><?=Html::a('Cursos', ['curso/index'])?></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Libro de Clases <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><?=Html::a('Alumnos', ['alumno/index'])?></li>
<li><?=Html::a('Notas', ['nota/index'])?></li>
<li><?=Html::a('Apoderados', ['apoderado/index'])?></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Cuenta <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><?=Html::a('Perfil('.Yii::$app->user->identity->username.')', ['site/alumno'])?></li>
<li><?=Html::a('Cerrar Sesión', ['site/logout'], ['data-method' => 'post'])?></li>
</ul>
</li>
<?php } else if (User::isUserApoderado (Yii::$app->user->identity->id)){?>
<li class="active"><?=Html::a('Calendario', ['calendario/index'])?></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Área Docente <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><?=Html::a('Profesores', ['profesor/index'])?></li>
<li><?=Html::a('Asignatura', ['asignatura/index'])?></li>
<li><?=Html::a('Cursos', ['curso/index'])?></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Libro de Clases <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><?=Html::a('Alumnos', ['alumno/index'])?></li>
<li><?=Html::a('Notas', ['nota/index'])?></li>
<li><?=Html::a('Apoderados', ['apoderado/index'])?></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Cuenta <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><?=Html::a('Perfil('.Yii::$app->user->identity->username.')', ['site/apoderado'])?></li>
<li><?=Html::a('Cerrar Sesión', ['site/logout'], ['data-method' => 'post'])?></li>
</ul>
</li>
<?php } ?>
</ul>
</div>
<!--/.nav-collapse -->
</div>
</div>
<header id="head" class="secondary">
<div class="container">
<h1><?= Html::encode($this->title) ?></h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing eliras scele!</p>
</div>
</header>
<div class="wrap">
<div class="container">
<?= Breadcrumbs::widget([
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
]) ?>
<?= Alert::widget() ?>
<?= $content ?>
</div>
</div>
<footer id="footer">
<div class="footer2">
<div class="container">
<div class="row">
<div class="col-md-6 panel">
<div class="panel-body">
<p class="simplenav">
<a href="index.html">Home</a> |
<a href="about.html">About</a> |
<a href="courses.html">Courses</a> |
<a href="price.html">Price</a> |
<a href="videos.html">Videos</a> |
<a href="contact.html">Contact</a>
</p>
</div>
</div>
<div class="col-md-6 panel">
<div class="panel-body">
<p class="text-right">
Copyright © 2014. Template by <a href="http://webthemez.com/" rel="develop">WebThemez.com</a>
</p>
</div>
</div>
</div>
<!-- /row of panels -->
</div>
</div>
</footer>
<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>
Related Topics
How Come Checkbox State Is Not Always Passed Along to PHP Script
Retrieve (Or Simulate) Full Query from Pdo Prepared Statement
3Rd Party Dependency Conflict in Developing Wordpress Plugin
How to Prevent from Printscreen of My Webpage
In PHP, How to Check If a Function Exists
How to Get the Last N Items in a PHP Array as Another Array
How to Get the Value of a Private Property with Reflection
%2F in Url Breaks and Does Not Reference to the .PHP File Required
How to Handle Diacritics (Accents) When Rewriting 'Pretty Urls'
PHP Strtotime +1 Month Behaviour
How to Calculate Time Difference in PHP
PHP Regex to Get String Inside Href Tag
Disable Browser Cache in PHP or JavaScript in a Flash Application
Getting a PHP Pdo Connection from a MySQL_Connect()
Getting the Value of an Extra Pivot Table Column Laravel