Adding additional nav menus in Sage

Hello ladies and gents,

I’ve been trying to troubleshoot such a simple task before moving to blade but now I am feeling the learning curve of adapting to blade templates so I’m seeking your help in overcoming the hump.

I’m trying to create additional menus like so:

In setup.php I have:

register_nav_menus( array(
    'primary_navigation' => __('Primary Navigation', 'sage'),
    'about_navigation' => __('About Navigation', 'sage'),
    'company_navigation' => __('Company Navigation', 'sage'),
    'shop_navigation' => __('Shop Navigation', 'sage'),
    'social_navigation' => __('Social Navigation', 'sage'),
) );

Within App.php I have:

<?php

namespace App\Controllers;

use Sober\Controller\Controller;

class App extends Controller
{
    public function siteName()
    {
        return get_bloginfo('name');
    }
    public function primarymenu() {
        $args = array(
            'theme_location'    => 'primary_navigation',
            'menu'  =>  '',
            'container' => 'span',
            'container_class' => 'container_class',
            'container_id' => 'container_id',
            'menu_class' => 'navbar-nav u-header__navbar-nav',
            'menu_id' => 'menu_id',
        //   'echo' => '',
        //   'fallback_cb' => '',
            'before' => '',
            'after' => '',
            'link_before' => '',
            'link_after' => '<span class="fa fa-angle-right u-header__sub-menu-nav-link-icon"></span>',
            // 'items_wrap' => 'item_wrap',
        //   'depth' => '',
            'walker' => new \App\wp_bootstrap4_navwalker()
        );
        return $args;
    }
    public function aboutMenu() {
        $aboutMenuArgs = array(
            'theme_location'    => 'about_navigation',
            'menu'  =>  '',
            'container' => 'a',
            'container_class' => 'list-group-item list-group-item-action',
            'container_id' => 'container_id',
            'menu_class' => 'list-group list-group-flush list-group-transparent',
            'menu_id' => 'menu_id',
        //   'echo' => '',
        //   'fallback_cb' => '',
            'before' => '',
            'after' => '',
            'link_before' => '',
            'link_after' => '',
            // 'items_wrap' => 'item_wrap',
        //   'depth' => '',
            // 'walker' => ''
        );
        return $aboutMenuArgs;
    }
    public function companyMenu() {
        $args = array(
            'theme_location'    => 'company_navigation',
            'menu'  =>  '',
            'container' => 'a',
            'container_class' => 'list-group-item list-group-item-action',
            'container_id' => 'container_id',
            'menu_class' => 'list-group list-group-flush list-group-transparent',
            'menu_id' => 'menu_id',
        //   'echo' => '',
        //   'fallback_cb' => '',
            'before' => '',
            'after' => '',
            'link_before' => '',
            'link_after' => '',
            // 'items_wrap' => 'item_wrap',
        //   'depth' => '',
            // 'walker' => ''
        );
        return $args;
    }
    public function shopMenu() {
        $args = array(
            'theme_location'    => 'shop_navigation',
            'menu'  =>  '',
            'container' => 'a',
            'container_class' => 'list-group-item list-group-item-action',
            'container_id' => 'container_id',
            'menu_class' => 'list-group list-group-flush list-group-transparent',
            'menu_id' => 'menu_id',
        //   'echo' => '',
        //   'fallback_cb' => '',
            'before' => '',
            'after' => '',
            'link_before' => '',
            'link_after' => '',
            // 'items_wrap' => 'item_wrap',
        //   'depth' => '',
            // 'walker' => ''
        );
        return $args;
    }
    public function socialMenu() {
        $args = array(
            'theme_location'    => 'social_navigation',
            'menu'  =>  '',
            'container' => 'a',
            'container_class' => 'list-group-item list-group-item-action',
            'container_id' => 'container_id',
            'menu_class' => 'list-group list-group-flush list-group-transparent',
            'menu_id' => 'menu_id',
        //   'echo' => '',
        //   'fallback_cb' => '',
            'before' => '',
            'after' => '',
            'link_before' => '',
            'link_after' => '',
            // 'items_wrap' => 'item_wrap',
        //   'depth' => '',
            // 'walker' => ''
        );
        return $args;
    }
}
/**
 * Primary Nav Menu arguments
 * @return array
 */

And finally, within the *.blade.php file I’m calling the menus like so:

  @if (has_nav_menu('about_navigation'))
        {!! wp_nav_menu($aboutMenu) !!}
  @endif

Yet I end up with an error like this:

Thank you in advance. Andrew.

Change wp_nav_menu($aboutMenu) to wp_nav_menu($about_menu). Controller will turn your methods to variables (camel case to snake case)

3 Likes

What a legend! That did it. Wish I would have posted earlier. I’m curious, how did you learn about this, is it covered in the documentation somewhere? Thank you so much for taking the time to respond.

No problem. The Sage docs mention about the usage of Controller. Looking at the docs of Controller it explains the usage of methods and variables.

1 Like

Not to sound like a shill but @ben’s book on Sage helped me out immensely. The docs are great but the book is totally worth the asking price imo.

6 Likes

This topic was automatically closed after 42 days. New replies are no longer allowed.