diff --git a/README.md b/README.md index e870333..9705d69 100644 --- a/README.md +++ b/README.md @@ -181,39 +181,35 @@ Here is the list of available skins: "skin-green-light" ``` -#### Disabling skin file loading, when using bundled assets +### Layout - Yii::$container->set( - AdminLteAsset::className(), - [ - 'skin' => false, - ] - ); +By default the extension uses default layout for AdminLTE. You can change it in config file. -If you want to use native DOM of headers AdminLTE - -```html -

- About static page -

+```php +'components' => [ + 'assetManager' => [ + 'bundles' => [ + 'dmstr\web\AdminLteAsset' => [ + 'layout' => dmstr\helpers\AdminLteHelper::LAYOUT_OPTION_FIXED, + ], + ], + ], +], ``` -then you can follow the code: - -```php -/* @var $this yii\web\View */ +**Note:** Best way to set layout option is to use options constants from `AdminLteHelper`. -$this->params['breadcrumbs'][] = 'About'; +And then just add class specific for layout to body. You can use `AdminLteHelper::layoutHtmlClass()` if you want to get always correct html class and don't want to alter every view file when you change layout option. +```html + +``` -$this->beginBlock('content-header'); ?> -About static page -endBlock(); ?> +#### Template Examples -
-

This is the About page. You may modify the following file to customize its content:

- -
-``` +* [Fixed](https://adminlte.io/themes/AdminLTE/pages/layout/fixed.html) +* [Collapsed Sidebar](https://adminlte.io/themes/AdminLTE/pages/layout/collapsed-sidebar.html) +* [Boxed Layout](https://adminlte.io/themes/AdminLTE/pages/layout/boxed.html) +* [Top Navigation](https://adminlte.io/themes/AdminLTE/pages/layout/top-nav.html) ### Left sidebar menu - Widget Menu diff --git a/helpers/AdminLteHelper.php b/helpers/AdminLteHelper.php index f663295..65c710f 100644 --- a/helpers/AdminLteHelper.php +++ b/helpers/AdminLteHelper.php @@ -5,7 +5,12 @@ class AdminLteHelper { - /** + const LAYOUT_OPTION_FIXED = 'fixed'; + const LAYOUT_OPTION_COLLAPSED_SIDEBAR = 'sidebar-collapse'; + const LAYOUT_OPTION_BOXED_LAYOUT = 'boxed'; + const LAYOUT_OPTION_TOP_NAVIGATION = 'top-nav'; + + /** * It allows you to get the name of the css class. * You can add the appropriate class to the body tag for dynamic change the template's appearance. * Note: Use this fucntion only if you override the skin through configuration. @@ -20,4 +25,33 @@ public static function skinClass() return $bundle->skin; } + + /** + * It allows you to get the name of the layout wrapper html class. + * You can add the appropriate class to the body tag for dynamic change the template's appearance. + * + * @return string + */ + public static function layoutHtmlClass() + { + /** @var \dmstr\web\AdminLteAsset $bundle */ + $bundle = Yii::$app->assetManager->getBundle('dmstr\web\AdminLteAsset'); + + return ($layout = $bundle->layout) ? self::getLayoutHtmlClassOptions()[$layout] : ''; + } + + /** + * Get layout wrapper html classes options + * + * @return array + */ + public static function getLayoutHtmlClassOptions() + { + return [ + self::LAYOUT_OPTION_FIXED => 'fixed', + self::LAYOUT_OPTION_COLLAPSED_SIDEBAR => 'sidebar-collapse', + self::LAYOUT_OPTION_BOXED_LAYOUT => 'layout-boxed', + self::LAYOUT_OPTION_TOP_NAVIGATION => 'layout-top-nav', + ]; + } } diff --git a/web/AdminLteAsset.php b/web/AdminLteAsset.php index 0173beb..85455e2 100644 --- a/web/AdminLteAsset.php +++ b/web/AdminLteAsset.php @@ -1,7 +1,9 @@ css[] = sprintf('css/skins/%s.min.css', $this->skin); } + // Append layout options + if ($layout = $this->layout) { + if (!array_key_exists($layout, AdminLteHelper::getLayoutHtmlClassOptions())) { + throw new InvalidConfigException('Invalid layout specified'); + } + + $layoutExtraAssetsOptions = self::getLayoutExtraAssetsOptions(); + if (array_key_exists($layout, $layoutExtraAssetsOptions)) { + if (isset($layoutExtraAssetsOptions[$layout]['js'])) { + $this->js = array_merge($this->js, $layoutExtraAssetsOptions[$layout]['js']); + } + if (isset($layoutExtraAssetsOptions[$layout]['css'])) { + $this->css = array_merge($this->css, $layoutExtraAssetsOptions[$layout]['css']); + } + if (isset($layoutExtraAssetsOptions[$layout]['depends'])) { + $this->depends = array_merge($this->depends, $layoutExtraAssetsOptions[$layout]['depends']); + } + } + } + parent::init(); } + + /** + * Get extra scripts and styles options needed to specific layout + * + * @return array + */ + public static function getLayoutExtraAssetsOptions() + { + return [ + AdminLteHelper::LAYOUT_OPTION_FIXED => [ + 'depends' => [ + AdminLteFixedLayoutAsset::class + ] + ], + ]; + } } diff --git a/web/AdminLteFixedLayoutAsset.php b/web/AdminLteFixedLayoutAsset.php new file mode 100644 index 0000000..479cd17 --- /dev/null +++ b/web/AdminLteFixedLayoutAsset.php @@ -0,0 +1,17 @@ +