Blade Navigation - Getting Entry Relationship in Standard Nav Item #8656
-
Hi all 👋 I'm building out a nav using blade and I've got it all working no dramas, but then I figured I wanted the client to simply set the Entry relationship to the page (eg Home, Contact etc) rather than manually set the navigation URL which seemed like a waste of time and double ups, but the data just doesn't look right to me, and I can't get the URL, Slug or anything. Note that I don't want to use the "Link to entry" because you can't set additional fields with them. So I use the standard nav item, with an additional "entry" field type relationship. My nav loop (returns array of items): Then to get the entry: Returns:
So I call An example return from a basic 'Contact' page where the url is
So when you look at the above, the I just want to get that entry relationship. Am I missing something really simple? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I worked out that I can use the
And ended up with something like:
Hate this though cause you're doing N+1 on each navigation item. And you have to re-do this code for any sub items with relationships. Again, I've got to be missing something here. Why aren't relationships eager loaded in Nav? There's entry relationship field type so they should. |
Beta Was this translation helpful? Give feedback.
-
I think I might be on to something here after reading through the core code... if I change the default relationship field slug from "entry" to anything else, then I can access it like |
Beta Was this translation helpful? Give feedback.
I think I might be on to something here after reading through the core code... if I change the default relationship field slug from "entry" to anything else, then I can access it like
$item['fieldName']
to get backStatamic\Entries\Entry
.