chrizus / arraymenu
从列表项数组创建嵌套菜单。
dev-master
2023-10-16 19:58 UTC
Requires
- php: ^8.1
Requires (Dev)
- phpunit/phpunit: ^10
This package is auto-updated.
Last update: 2024-09-16 22:01:26 UTC
README
此包已为个人使用分支。请访问原始包wtabata/arraymenu
ArrayMenu 2
从 array[] 构建菜单/导航栏 Bootstrap 5
安装
composer require chrizus/arraymenu
简单模式
将构建 标准HTML列表 结构
$array = [ 'home' => [ 'name' => 'Label for Home', 'link' => '#', ], [ /* << see, here don't have key. no matter. just for help u */ 'name' => 'Label for Contact' ], ]; $menu = new \BergPlaza\ArrayMenu\Simple($array); echo $menu;
输出
<ol class="more_class my_class"> <li class=""><a class="" href="#">Label for Home</a></li> <li class="">Label for Contact</li> </ol>
默认列表标签
<ul> <!-- init - primary tag --> <li> <!-- item - secondary tag --> <a href="#"> - </a> <!-- link - content --> </li> </ul>
两种配置标签的方式
全局
//set primary Tag $menu->setInit(['tag'=>'ol', 'class' =>'my_class']); //set secondary Tag $menu_b->setItem(['tag'=>'li', 'class' =>'my_class_for_item other']);
或每个项目
$array = [ 'config' => [ //set primary Tag 'tag' => 'ol', 'class' => 'my_class' ], 'home' => [ 'config' => [ //set secondary Tag 'tag' => 'dd', 'class' =>'my_class_for_item other' ], 'name' => 'Label for Home', 'link' => '#', ], ];
Bootstrap 5 模式
将构建 Bootstrap 5 导航栏 结构
$array = [ 'home' => [ 'name' => 'Label for Home', 'link' => '#', 'class' => 'nav-link', ], 'contact' => [ 'name' => 'Label for Contact', 'link' => '#', 'class' => 'nav-link', ], 'sitemap' => [ 'name' => 'Label for Sitemap', 'link' => '#', 'class' => 'nav-link active', ] ]; $menu = new \BergPlaza\ArrayMenu\Bootstrap($array, $config_bootstrap = []); echo $menu;
Bootstrap 5 默认配置
$config_bootstrap = [ 'position' => 'default', 'color' => 'bg-primary', 'container' => 'container', 'brand' => [ 'name' => 'WT.dev', 'image' => false, 'link' => 'https://wtabata.com' ], 'off_canvas' => false ];
待办事项
文档
- 简单用法
- 与 Bootstrap 一起使用
- 默认标签
- 自定义标签
- 基础选项
- Bootstrap 选项
基础
- 其他非标准标签
Bootstrap
- 滚动