7rin0/bigfoot-navigation-bundle
Installation
Add the bundle to your composer.json:
composer require 7rin0/bigfoot-navigation-bundle
Enable it in config/bundles.php:
return [
// ...
SevenRin0\BigfootNavigationBundle\SevenRin0BigfootNavigationBundle::class => ['all' => true],
];
Basic Configuration
Configure the bundle in config/packages/bigfoot_navigation.yaml:
seven_rin0_bigfoot_navigation:
theme: 'default' # or your custom theme
menu_items: [] # Define your menu structure here
First Use Case: Rendering a Menu
Use the bigfoot_navigation Twig function in your templates:
{{ bigfoot_navigation('main_menu') }}
Ensure you’ve defined main_menu in your config.
Define menus in YAML (e.g., config/packages/bigfoot_navigation.yaml):
seven_rin0_bigfoot_navigation:
menus:
main_menu:
items:
- label: 'Home'
uri: '/'
active: true
- label: 'About'
uri: '/about'
children:
- label: 'Team'
uri: '/about/team'
Inject the NavigationManager service to build menus programmatically:
// src/Service/MenuBuilder.php
use SevenRin0\BigfootNavigationBundle\Manager\NavigationManager;
class MenuBuilder
{
public function __construct(private NavigationManager $navigationManager) {}
public function buildAdminMenu(): array
{
return [
'items' => [
['label' => 'Dashboard', 'uri' => '/admin'],
['label' => 'Users', 'uri' => '/admin/users'],
],
];
}
}
Register the menu in a compiler pass or config.
Override default templates by copying them from:
vendor/sevenrin0/bigfoot-navigation-bundle/Resources/views/
to:
templates/bundles/bigfootnavigation/.
Customize Twig templates (e.g., menu.html.twig) to match your design.
Use the active flag in menu items or leverage Twig’s is_active logic:
{% for item in menu.items %}
<li class="{{ 'active' if app.request.get('_route') == item.uri|route }}">{{ item.label }}</li>
{% endfor %}
Pass route names instead of URIs for dynamic path generation:
items:
- label: 'Products'
route: 'app_product_index'
Symfony 3 Only This bundle is Symfony 3.x-only. Avoid using it in Symfony 4+ without compatibility checks.
YAML Configuration Overrides If menus don’t render, verify:
theme key in config matches an existing theme (default or custom).menus: (not menu_items: in older versions).Twig Function Scope
bigfoot_navigation() requires a registered menu name. Undefined names throw Twig\Error\RuntimeError.
Caching Issues Clear cache after config changes:
php bin/console cache:clear
dump() to inspect the rendered menu:
{{ dump(bigfoot_navigation('main_menu')) }}
php bin/console debug:config seven_rin0_bigfoot_navigation
to verify loaded menus.Custom Themes
Extend the default theme by copying Resources/public/ assets to your project’s web/ and updating the theme config.
Event Listeners
Subscribe to bigfoot.navigation.build events to modify menus dynamically:
// src/EventListener/MenuModifier.php
use SevenRin0\BigfootNavigationBundle\Event\MenuEvent;
class MenuModifier implements EventSubscriber
{
public static function getSubscribedEvents(): array
{
return [MenuEvent::BUILD => 'onBuildMenu'];
}
public function onBuildMenu(MenuEvent $event): void
{
$event->getMenu()->addItem(['label' => 'Dynamic Item', 'uri' => '/dynamic']);
}
}
Database-Driven Menus Fetch menu items from a database in a compiler pass and merge them into the config:
// src/DependencyInjection/Compiler/DynamicMenuPass.php
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class DynamicMenuPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container): void
{
$menuItems = $this->fetchFromDatabase();
$container->getDefinition('bigfoot_navigation.manager')
->addMethodCall('setDynamicItems', [$menuItems]);
}
}
DISTINCT queries).How can I help you explore Laravel packages today?