Closed andrewebdev closed 3 years ago
@andrewebdev the page for a menu item should always be accessible from the template.
For top-level menu items, the the menu item will be a MenuItem
instance, with the page available via the link_page
field, so menu_item.link_page.highlight_color
should work.
For menu items generated from pages, the menu items are actually specific page instances with attributes added, so menu_item.highlight_color
should work.
What would be the best way to add a extra property to the some menu items? I had a look at the hooks, but there is no clear hook to do this.
My issue is that I have a property on some of my pages which should change the menu item CSS. These can change between pages. I can grab the page_id from the menu_item, do a lookup for that property on the page from there, but this will cause extra database queries that I'd prefer to avoid.
I tried the following:
But of course this doesn't work because, when the menu_items are primed, this value is not added. I just want a way to add
highlight_color
to the menu_item context.