-
-
Notifications
You must be signed in to change notification settings - Fork 506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] MenuItem current property is always false in global context. #3000
Comments
Hi @xanghyr , welcome at Timber! I just recreated your issue on Timber 2.2 (just released) but I don't run into this issue.
Could you try debugging this further? Maybe create another menu with other menu items and query that menu? |
Hello, thank you ! So I created a new clean & simple project from my boilerplate to test menus, and it works great... I don't know if it's a good news or a bad news ^^ Thank you anyway, i'll debug this further and come back here if I find anything interesting. |
Thank you for your feedback @xanghyr, let me know if you find something interesting. Maybe try to change the name of menu names or menu locations and see if that helps! I'll close this issue for now but feel free to respond to this if you find something. |
Hi, I'm back after I've been able to spend some time to fix my issue. So the thing was that I had a feature required in So of course menus did not worked as it gets them before |
Expected Behavior
Should setup
current
current_item_parent
current_item_ancestor
with the good values.Actual behavior
MenuItem properties :
current
current_item_parent
current_item_ancestor
are alwaysfalse
.Steps to reproduce behavior
{{ dump(menu) }}
in your template. Search for current property inside MenuItem.Notes
It felt weird as I don't remember having this bug in my previous WordPress/Timber, though it's my first time using Timber 2.x. So I did some research to find the origin.
I found that for the 3 MenuItem properties
$current
$current_item_parent
$current_item_ancestor
they use the native WordPress function_wp_menu_item_classes_by_context()
.This function is using the
global $wp_query;
to setup those properties.And I found that in the filter
timber/context
(add_filter( 'timber/context', array( $this, 'add_to_context' ) );
) theglobal $wp_query;
is not already set. This global is only set later, available withadd_action( 'wp', array( $this, 'test_global_wp_query' ) );
. But at this point you can't add variable to the global context, at least not that I know of.When I do
$context['header_menu'] = Timber::get_menu('header_menu');
inside a template, just beforeTimber::render()
the properties current, etc. are all good. But I don't feel like it would a good solution to use some kind of function in every template I have to get the menus at this moment.I think that menus are meant to be inside the global context, if that so, any idea on how to fix this ?
Thank you !
What version of Timber are you using?
2.1.0
What version of WordPress are you using?
6.5.3
What version of PHP are you using?
8.2
How did you install Timber?
Installed or updated Timber through Composer
The text was updated successfully, but these errors were encountered: