From b97482c64265c73419abda428178ddb990a84b8c Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Wed, 17 Feb 2021 23:30:58 +0000 Subject: [PATCH] Task 5 - Refactor menu items using a loop --- config/packages/twig.yaml | 2 ++ src/Repository/MenuItemArrayRepository.php | 34 ++++++++++++++++++++++ src/Repository/MenuItemRepository.php | 8 +++++ templates/includes/navbar.html.twig | 16 ++++++---- 4 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 src/Repository/MenuItemArrayRepository.php create mode 100644 src/Repository/MenuItemRepository.php diff --git a/config/packages/twig.yaml b/config/packages/twig.yaml index b3cdf30..c9409a4 100644 --- a/config/packages/twig.yaml +++ b/config/packages/twig.yaml @@ -1,2 +1,4 @@ twig: default_path: '%kernel.project_dir%/templates' + globals: + menu_items: '@App\Repository\MenuItemRepository' diff --git a/src/Repository/MenuItemArrayRepository.php b/src/Repository/MenuItemArrayRepository.php new file mode 100644 index 0000000..a0f0647 --- /dev/null +++ b/src/Repository/MenuItemArrayRepository.php @@ -0,0 +1,34 @@ + 'Conference', + 'is_active' => false, + ], + [ + 'title' => 'Sponsors', + 'is_active' => false, + ], + [ + 'title' => 'Community', + 'is_active' => false, + ], + [ + 'title' => 'FAQ', + 'is_active' => false, + ], + [ + 'title' => 'Register', + 'is_active' => true, + ], + ]; + } +} diff --git a/src/Repository/MenuItemRepository.php b/src/Repository/MenuItemRepository.php new file mode 100644 index 0000000..830e464 --- /dev/null +++ b/src/Repository/MenuItemRepository.php @@ -0,0 +1,8 @@ +