Having a VERY hard time with menus

So, trying to use Contentbox after many years. I have a template I bought from WrapBootstrap and am trying to slide-n-dice into a Coldbox theme. (Docs on this are… insufficient. Just having to figure it all out. No real walkthrough.)

In the default, primary theme that Contentbox installs, as I tear through it I find this line:
<cfset menuData = cb.rootMenu( type=“data”, levels=“2” )>

This “rootMenu” is simpy based on what’s in the CMS. There is example code in the theme\xxx\views_header.cfm file to build out a menu… based on what rootMenu() returns.

But Contentbox allows you to build your OWN menus. Yay! So I did. Let’s call that menu “global”.

The only way to get to this menu, in code that I’ve found is menuService.findBySlug(‘global’).

The object returned by rootMenu() and the object returned by findBySlug() are NOT the same kind of thing. The code used in that _header file is based on how rootMenu returns, and does NOT work for findBySlug().

I have spent TWO FULL days trying to understand the different types of menu items, and how the submenus apply so I can build a renderer. I am NOT having fun anymore. Things just don’t quite work like I’d expect.

So, the QUESTION:
Is there either:

  • a way to convert the findBySlug() return to match the rootMenu() return format
    or
  • any sample code to build out a menu (where your template has to be different than Contentbox default templates) that are based on findBySlug() style.
    or
  • a way to retrieve a custom menu in the format returned by cb.rootMenu()

Any help would be much appreciated. I’m about ready to give up on slicing and dicing an external template into Contentbox theme style so I can NOT build a bunch of custom code and use what Ortus has built.

Contenbox 4.2.1 on latest Coldbox.

Hi Will

These are the main menu building helpers in the cbHelper. If you go to core services, then you need to follow the API those services give you. However, the cbHelper should be sufficient to build any theme you create:

  • rootMenu() - Used to build out quick menu’s based on the root level pages hierarchy. It can return back to you the full HTML menu or a the struct literal representation of the menu (type=data)

  • subPageMenu() - Used to build out a menu based on a page’s children. Same as rootMenu() but rooted at a specific page. Type=data also applies here for full control.

  • menu() - Searches the menu’s you created in ContentBox and gives you back a representation of that menu in type=“html” or type=“data”.

If you use findBySlug() then you are going to get the object that represents the menu hierarchy.

Luis, thanks for the reply. Unfortunately, I gave up on Contentbox for this project. Just didn’t have time to fool with it anymore.

Luis – back at it. This helped me immensely. cb.menu(slug: ‘top-nav’, type: ‘data’) is exactly what I needed, thank you.

1 Like