Dynamic Menu Extension
Dynamically Extending the Sidebar Menu
A guide to adding application-specific menu items using menu_extension.php.
The application is designed with a multi-app architecture, allowing you to create distinct "setups" (like "INtex Adressen") that share a common core but have their own branding, features, and menu items.
One of the key extension points is the main sidebar menu. You can dynamically inject new menu items for a specific setup without modifying the core menu.php file. This is achieved by creating a special file named menu_extension.php inside your setup's dedicated folder.
The core file menu.php contains a specific line of code that looks for and includes your extension file:
<?php
// --- NEU: Dynamische Menü-Erweiterung aus dem Setup-Ordner laden ---
include_setup_file('menu_extension.php');
?>
The include_setup_file() function (defined in init.php) performs the following steps:
- It checks if a
SETUP_FOLDERconstant is defined in yourconfig.php. - If it is, the function looks for a file named
menu_extension.phpinside that folder (e.g.,setup_adressen/menu_extension.php). - If the file exists, its content is directly included into the sidebar menu's HTML structure.
Step 1: Define your Setup Folder
In your config.php, make sure you have a setup defined with a SETUP_FOLDER constant. For example:
// In config.php
define('SETUP_CHOICE', 'INtex Adressen');
switch (SETUP_CHOICE) {
case 'INtex Adressen':
define('SETUP_NAME', 'INtex Adressen');
define('SETUP_FOLDER', 'setup_adressen'); // This is the crucial part
// ... other constants
break;
}
Step 2: Create the Extension File
Create a new file inside the folder you just defined. The path must be exactly:
setup_adressen/menu_extension.php
Step 3: Add Your Menu Items
Open the new menu_extension.php file and add your menu items as HTML list items (<li>). The structure should match the existing items in menu.php.
Each menu item typically consists of:
- A list item with the class
sidebar-item. - A link (
<a>) with the classsidebar-link. - An icon (
<i>) from Font Awesome with thefa-fwclass for fixed width. - A span (
<span>) with the classsidebar-textfor the menu label.
href attributes must be relative to the application's root directory (where index.php is located), not relative to the setup_adressen folder.
Here is a complete example for your setup_adressen/menu_extension.php file. You can copy and paste this code and adapt it to your needs.
<?php
// This file is dynamically included in menu.php.
// It allows adding application-specific menu items.
?>
<!-- A divider to visually separate the new items -->
<li class="sidebar-divider"></li>
<!-- First custom menu item -->
<li class="sidebar-item">
<a class="sidebar-link" href="setup_adressen/wv.php">
<i class="fa-solid fa-calendar-day fa-fw icon-example"></i>
<span class="sidebar-text">Follow-Up</span>
</a>
</li>
<!-- Second custom menu item -->
<li class="sidebar-item">
<a class="sidebar-link" href="setup_adressen/tutorial.php">
<i class="fa-solid fa-circle-question fa-fw icon-example"></i>
<span class="sidebar-text">Assistant</span>
</a>
</li>
After saving this file, the new menu items "Follow-Up" and "Assistant" will automatically appear in the sidebar menu whenever the "INtex Adressen" setup is active.