PHP code example of shallowred / kirby-navigation-menus

1. Go to this page and download the library: Download shallowred/kirby-navigation-menus library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

shallowred / kirby-navigation-menus example snippets


// site/config/config.php
return [
    'shallowred.navigation-menus.declared-navigation-menus' => [
        'main' => [
            'name' => 'main_navigation',
            'label' => 'Main Navigation'
        ],
        'footer' => [
            'name' => 'footer_navigation',
            'label' => 'Footer Navigation'
        ]
    ]
];

<!-- Display main navigation -->
 foreach (site()->getMenu('main')->toBlocks() as $block): 

return [
    'shallowred.navigation-menus.defaults' => [
        'aria-label' => 'Main navigation',
        'layout' => 'horizontal',
        'has-toggler' => true,
        'wrapper' => 'nav',
        'auto-current-detection' => true,
        'button-variant' => 'primary',
    ]
];

return [
    'shallowred.navigation-menus.css' => [
        'current-page-class' => 'active',
        'nav-toggler-class' => 'menu-toggle',
        'dropdown-class' => 'dropdown-menu',
        'mobile-nav-class' => 'mobile-navigation',
        'show-current-icon' => true,
        'current-icon-html' => '<span class="current-indicator" aria-hidden="true">→</span>',
    ]
];

return [
    'shallowred.navigation-menus.security' => [
        'allow-external-links' => true,
        'allowed-schemes' => ['https', 'http', 'mailto', 'tel'],
        'max-dropdown-depth' => 2,
        'secure-external-links' => true,
    ]
];

return [
    'shallowred.navigation-menus.mobile' => [
        'breakpoint' => '768px',
        'close-on-outside-click' => true,
    ],
    'shallowred.navigation-menus.accessibility' => [
        'enable-skip-link' => true,
        'skip-link-text' => 'Skip to main content',
        'focus-management' => true,
        'aria-expanded' => true,
    ]
];

$mainNav = site()->getMenu('main');
if ($mainNav) {
    echo $mainNav->toBlocks();
}

$navPages = site()->navPages('main');
foreach ($navPages as $navPage) {
    echo site()->renderNavItem($navPage, $page);
}

echo site()->renderNavItem($navPage, $page);

if (site()->isValidUrl($url)) {
    // URL is safe to use
}

if ($page->isInMenu('main')) {
    echo "This page is in the main navigation";
}

$prevPage = $page->prevInMenu('main');
$nextPage = $page->nextInMenu('main');

if ($prevPage): 

 if ($page->hasPrevInMenu('main')): 

<!-- Custom navigation with advanced features -->
 $navPages = site()->navPages('main') 

<!-- Enable breadcrumb mode in your navigation block -->
breadcrumb: true
layout: horizontal # Automatically set for breadcrumbs

return [
    'debug' => true,
    'shallowred.navigation-menus.debug.dev-warnings' => true,
    'shallowred.navigation-menus.debug.log-errors' => true,
];

// site/languages/de.php
return [
    'shallowred.navigation-menus.navigation.aria-label' => 'Hauptnavigation',
    // Add more translations...
];