Navbar Dropdown
Build responsive, multilingual-ready application navigation with reusable Bootstrap navbar components, direct links and optional dropdown menus.
Purpose
Navbar Dropdown provides a ready-to-integrate navigation bar for APPNETOS applications. Instead of implementing navigation markup, dropdown behavior and active-link handling in every application, developers configure a brand and a menu in their own Core App extension.
Menu labels can be supplied in different languages through the application's localization logic. The
Core
App itself does not automatically translate the menu: the application supplies the localized titles
through getMenu() and, if needed, getBrand().
Capabilities
- Responsive Bootstrap navigation with an optional brand title and logo.
- Direct navigation links and single-level dropdown menus.
- Optional dropdown separators, disabled links and link targets.
- Exact-path active-link detection for eligible same-host links.
- Application-defined menu labels suitable for multilingual navigation.
- Replaceable Bootstrap-version-specific Twig templates.
Dropdown parents are not marked active based on their children. Titles may contain HTML and must therefore be supplied from trusted sources.
Integration in an application
Create an application-specific class that extends CoreApp\Navigation\NavbarDropdown.
Override the brand and menu configuration, and optionally route the rendered result into a View
Slot. In
APPNETOS Docs, the navigation is prepended to frameset_top.
use CoreApp\Navigation\NavbarDropdown as CoreAppNavbarDropdown;
use Core\Render\ViewSlot;
class NavbarDropdown extends CoreAppNavbarDropdown
{
public function __invoke(): ViewSlot
{
$view = parent::__invoke();
return $this->getViewSlot((string) ($view ?? ''));
}
protected function getBrand(): array
{
return [
'title' => 'My Application',
'image' => null,
'link' => $this->getContextUrl(),
];
}
protected function getMenu(): array
{
return [
[
'title' => 'Home',
'link' => $this->getContextUrl(),
'dropdown' => [],
],
[
'title' => 'More',
'link' => null,
'dropdown' => [
['title' => 'Overview', 'link' => $this->getContextUrl() . '/overview'],
['divider' => true],
['title' => 'Help', 'link' => $this->getContextUrl() . '/help'],
],
],
];
}
}
The example follows the APPNETOS Docs integration pattern. Its
getViewSlot()
helper is application-specific and must be implemented when using this pattern.
Override methods
| Method | Purpose |
|---|---|
getBrand(): array |
Provides the brand title, optional image and destination link. Use application-specific branding or localized text. |
getMenu(): array |
Defines direct links and dropdown entries, including localized labels, separators, disabled states and optional targets. |
__invoke(): ViewSlot|string|null |
Renders the navigation. Override to place the parent-rendered output in an application View Slot or adjust integration behavior. |
getBaseTemplate(): string |
Selects the Twig template used for the navbar; override when replacing the standard template. |
getBootstrapTemplateDirectory(): string |
Resolves the Bootstrap-specific template directory. Can be customized for application-specific template locations. |
normalizeBootstrapTemplateVersion(BootstrapVersion|null $bootstrapVersion):
string |
Maps the configured Bootstrap version to a supported template version; extend deliberately when supporting additional versions. |
prepareMenu(...): array, prepareLink(...): array, normalizePath(...):
string |
Advanced customization points for menu processing and active-path matching. Usually no override is needed. |
Bootstrap and templates
The current Core App implementation explicitly supports Bootstrap 5.3 templates and requires the
hosting
application to provide Bootstrap CSS and bootstrap.bundle.min.js. The template
directory is
selected from the configured UI Bootstrap version; unsupported or disabled Bootstrap versions do not
silently fall back.
All templates can be replaced through the supported template selection methods. When new Bootstrap versions are added to the Core App, their templates can coexist with existing versions.
Source and related documentation
appnetos/shared/apps/navigation/navbar-dropdown/src/NavbarDropdown.php
See also App Content and View Slots.