Content delivery API best practises for navigation
f
Hi all 👋 , I'm building an NextJS website with the Content delivery API. 1) What are the best practise to create a multi level navigation, are you using a custom made API or is it possible to get it from the delivery API ? 2) Is it fine to do different API calls for one page if you want to load sub-content or other content? As it doesn't seems to be possible to fetch different pages in one call. Thanks for your inputs
I ended up not using the content delivery API, it seems it's not made for that
c
Hi @Florent Grandjean, depending on your use cases all of the above is possible using the content delivery API. For multi level navigation my go-to approach would be to create some sort of settings docType that allows you to specify the various links in your navigational. You can nest them accordingly, and fetch the settings through the API. It is also possible to fletch multiple pages in one call, both with the Query endpoint, and the endpoint that allows for a list of content IDs if you have a specific set of pages in mind
f
Hi @Corné Hoskam thanks for your answer. I wanted to use a multi url picker so navigation can be either a link or an anchor when it's a link it should also list the visible children. I haven't seen a parent-child selection property that could do the job. For the query, I tried but didn't see how to do that: For example I want my home page and 6 blog articles, I had to use 2 calls like: /umbraco/delivery/api/v1/content/item/home /umbraco/delivery/api/v1/content/?fetch=children:blog/articles&take=6 I could use Ids but didn't see that you can select more than one ?
c
Thinking out loud here, but I think you won't be able to resolve what you're trying to achieve just in one call, if you depend on it being an automatic process of selecting all children. The way I see you could get this to work would be if you were to create a set of nested properties on a document type that represent the navigation, in which you configure all the links in your navigation, including the children if you wish for them to be in your navigation
What you end up with is a single item, say /umbraco/delivery/api/v1/content/item/settings/navigation, that returns a content item with a property on it that contains links to all pages and sub-pages you wish to have in your navigation
f
I did a test with a gridBlock with Link picker and a nested list of the same gridblock as a children, it's working well indeed that's a good idea! The other question was how can you merge those 2 queries ? /umbraco/delivery/api/v1/content/item/home /umbraco/delivery/api/v1/content/?fetch=children:blog/articles&take=6 How can you select the content of sub-pages in the same call? Or it could also be a picker ? Thanks
c
I don't really know out of my head if the default filter options allow for that. Either you'd have to make some filter to both allow all blogs and a home page, or you could even make a custom filter type to do what you want it to (which should be possible, technically/code wise )
38 Views