get the name of a menu for output in theme

  • Hi,

    I have a theme and the mobile navigation should show multiple menus, as title I would like to use the one the user enters as name for the menu. Is this possible?

    Code
    1. $view->menu()->getname('')

    only returns "Menu" for every menu, but I'd like to have the user set title of the menu (not the position)

    Thanks in advance

  • sorry for beeing unclear, but thank you for your fast reply(s)

    I'll try it again:

    I want the title of the menu to be visible in the offcanvas menu of my theme.

    So the user can create multiple menus and name them and these names will be used as titles of the corresponding menus in offcanvas (so I've multiple menus in offcanvas, eg one for the pages, one for social, etc.; as the user likes)

  • The getName() method only returns the helper name which is menu.

    You cannot get the menu label within the menu helper.

    Try following:

    Code
    1. $app['menu']->getPositions()['menuPositionName']['label']

    The LORD is my strength and my shield; in him my heart trusts, and I am helped; my heart exults, and with my song I give thanks to him. Psalm 28,7

  • What I don't get is, the multiple menu thing. It's only possible to show a single menu in a menu position.


    The only thing to show multiple menus in a position, is with widget's. Simply create a menu, don't assign it to a menu position and create a menu widget, selecting the added menu. Proceed as many times you'd like to add a menu.

    The LORD is my strength and my shield; in him my heart trusts, and I am helped; my heart exults, and with my song I give thanks to him. Psalm 28,7

  • What I don't get is, the multiple menu thing. It's only possible to show a single menu in a menu position.


    The only thing to show multiple menus in a position, is with widget's. Simply create a menu, don't assign it to a menu position and create a menu widget, selecting the added menu. Proceed as many times you'd like to add a menu.

    Tha's i don't get too, why they don't made possible to enable multiple menues into offcanvas position for example. Well i do make a trick then with links, but it could have been fun right?

  • The getName() method only returns the helper name which is menu.

    You cannot get the menu label within the menu helper.

    Try following:

    Code
    1. $app['menu']->getPositions()['menuPositionName']['label']

    thank you very much!

    but this only retruns the name of the position (if I used it correctly), but this is kind of useless because I know the name of the position in the code, but not the name, the user has set for the menu

    the same goes for:

    Code
    1. $app['menu']->getPositions()['menuPositionName']['name']
  • Sorry, wrong advice ...


    The menus are saved in the system/site config. Hence you can use:

    $app->config('system/site')->get('menus') (1)


    But I think you can use the menu manager after all.

    Try for a single menu: $app['menu']->get($id)

    and for all menus: $app['menu']->all() (using this method instead of (1), you get also the associated menu positions)


    The LORD is my strength and my shield; in him my heart trusts, and I am helped; my heart exults, and with my song I give thanks to him. Psalm 28,7

  • thank you, but doesn't seem to work too

    $app->config('system/site')->get('main') and $app['menu']->get('main') with 'main' as the name of the menuposition don't return anything (just an empty string or something)

    $app->config('system/site')->get('menus') and $app['menu']->all() throw an error...


    also, I can't find the lines you cited from pagekit/app/system/modules/content/src/Plugin/SimplePlugin.php

  • ahh I found it in pagekit/app/system/modules/site/src/MenuManager.php

    and there follows on line 90: public function find($position)

    this is what I'm looking for, it finds an assigned menu by position

    the working command is therefore: $app['menu']->find('name_of_position')

    thank you very much SAB