mandev mandev - 3 months ago 35
PHP Question

How to add materialize in Yii2

I'm trying to add Materialize in my Advanced Yii2 Project.

and there is a sample template for this, but i can't even use it in my yii application

How can i add materialize css's in my main application?

is there a good tutorial about that?



It's quite easy to add materialize framework into your Yii2 App.

First way (Not suggested):

Copy all needed CSS and JS files into your public web directory. Then in your frontend\assets\AppAsset class add the following lines:

public $css = [
    //... another css files

public $js = [
    //... another js files

Another way would be using Yii2's Bower.

Most JavaScript/CSS packages are managed using Bower and/or NPM, instead of Composer. Yii uses the Composer asset plugin to enable managing these kinds of packages through Composer. If your extension depends on a Bower package, you can simply list the dependency in composer.json like the following:

// package dependencies
"require": {
    "bower-asset/jquery": ">=1.11.*"


bower install materialize

More Information (Yii2's Official Document): Bower and NPM Assets

It might also be remarkable that, you can define new Asset Bundle for your app, so, there is no need to modify AppAsset class. To create your own Asset Bundle check the following links:

Defining Asset Bundles and Using Asset Bundles

If you want to Disable bootstrap or JQuery from your app, you can check the following link:

Yii2 disable Bootstrap Js, JQuery and CSS