-
-
Notifications
You must be signed in to change notification settings - Fork 23
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
Query returns NULL in CP preview #384
Comments
That would be correct behaviour if there is no active node. You probably shouldn't assume that I'd adjust your templates to handle this with a conditional, or a null coalescing operator. {% set currentNavNodeId = craft.navigation.getActiveNode({ handle: 'mainMenu' }).id ?? null %} |
Thank you for replying. I could do that but would not be able to correctly render a preview. Why is there suddenly no |
I do mean that you should be doing that anyway, as you might be on a page that doesn't have an active node, and you'll run into this error sooner or later. As for why it doesn't work in preview, I'd say it's likely because we don't handle it, and we expect it to be a front-end request. I'll have a look into adding support for that. |
For the time being I have now resorted to hard code the ID into the templates → Thanks. |
Describe the bug
In my templates I am determining the current node id this way:
{% set currentNavNodeId = craft.navigation.getActiveNode({ handle: 'mainMenu' }).id %}
which works fine so far. The template breaks though in the CP's preview panel as well as the parameterised preview where craft adds info to the url (aka ?x-craft-preview=E8eOWX…) after applying any change to the entries content.
Steps to reproduce
Impossible to access an attribute ("id") on a null variable.
Craft CMS version
4.7.1
Plugin version
2.0.25
Multi-site?
Yes
Additional context
The navigation elements are entries.
The text was updated successfully, but these errors were encountered: