byte-artist/menu-bundle

为前端应用提供可配置的 symfony 和 twig 兼容菜单

安装: 21

依赖: 0

建议者: 0

安全: 0

星星: 1

关注者: 2

分支: 0

开放问题: 0

类型:symfony-bundle

0.1 2022-01-23 20:38 UTC

This package is auto-updated.

Last update: 2024-09-24 02:47:31 UTC


README

menu-bundle 是一个 symfony bundle,用于根据存储在 menu.yaml 中的配置显示菜单。如果页面当前活动,则系统已知路径下的 routes 被识别并显示为 "活动" 状态。如果菜单项的标签存储在翻译中,则进行翻译。

安装

确保全局安装了 Composer,如 Composer 文档中的 安装章节 所述。

使用 Symfony Flex 的应用程序

打开命令行,进入您的项目目录并执行

$ composer require byte-artist/menu-bundle

不使用 Symfony Flex 的应用程序

步骤 1:安装 Bundle

打开命令行,进入您的项目目录并执行以下命令以安装此 Bundle 的最新稳定版本

$ composer require byte-artist/menu-bundle

步骤 2:启用 Bundle

然后,通过将其添加到项目 config/bundles.php 文件中注册的 Bundle 列表中来启用该 Bundle

// config/bundles.php

return [
    // ...
    ByteArtist\MenuBundle\MenuBundle::class => ['all' => true],
];

配置

示例

menu:
    type: default
    brand_name: Brand Name
    use_orig_css: true
    use_orig_js: true
    pages:
        label_home:
            path: existing_route
        label_user:
            path: label_user_index
            pages:
                label_user_create:
                    path: route_user_create
                label_user_edit:
                    path: route_user_edit
        label_admin:
            path: #
            pages:
                label_admin_overview:
                    path: route_admin_index
                label_admin_edit:
                    path: route_admin_edit
        label_contact:
            path: route_content
        label_imprint: https://www.byte-artist.de/imprint
  • type:可能的类型:div、list、bootstrap 和默认(默认为 list)
  • brand_name:在 bootstrap 菜单中显示的品牌名称(仅限 bootstrap 类型)
  • use_orig_css:标志,用于控制是否应使用与 Bundle 一起提供的 css 代码,如果为 false,则必须自行提供
  • use_orig_js:标志,用于控制是否应使用与 Bundle 一起提供的 js 代码,如果为 false,则必须自行提供
  • pages:属于菜单的结构列表
    • route_name:菜单项的名称,如果它在翻译中存在,则进行翻译,否则将根据此处指定的方式显示该项

      [

      • path:现有动作的路线名称、正常 url 或仅 '#' 也是可能的。
      • pages:可选,任何子页面

      ]

使用

要显示菜单,只需在 Twig 模板中调用 menu Twig 函数,无论它在哪里显示即可

// layout.html.twig
{{ menu() }}

故障排除

如果出于某种原因 contrib recipes 的 symfony 存储库不可用,请在您的 composer.json 中添加以下行

"extra": {
    "symfony": {
        "endpoint": [
            "https://api.github.com/repos/mastercad/symfony-recipes/contents/index.json",
            "flex://defaults"
        ]
    }
}