Open samuells opened 4 years ago
Alternative for now as no alternativ was suggested: For this you can use the parent_id
and the Links API. This allows you to directly resolve the parent_id & therefore the upper parents: https://www.storyblok.com/docs/api/content-delivery#core-resources/links/retrieve-multiple-links
@DominikAngerer is there an example how that would look like? I don't see how that would look like with multiple links, you suggest to fetch all links and then how does the grandparents resolve?
Any news on this? I'm having so much troubles to get my breadcrumbs working. For the time being, it would be so great if we could have some example on how to get around with this.
@dohomi @deodat I'm fetching all the links from https://api.storyblok.com/v1/cdn/links
then searching all the parents in it.
sth like:
/**
* returns the parents of given `current` link
* @param links the result from the `https://api.storyblok.com/v1/cdn/links`
* @param current the current link you want to build the breadcrumbs for.
*/
function getParentLinks(links: Record<string, StoryBlokLink>, current: StoryBlokLink): StoryBlokLink[] {
const items: StoryBlokLink[] = Object.values(links)
const parents: StoryBlokLink[] = []
let parentId: number | undefined = current.parent_id
while (parentId) {
const parent = items.find((item) => item.id === parentId)
if (parent) {
parents.push(parent)
}
parentId = parent?.parent_id
}
return parents
}
Hey @simonmumenthaler, could you share how to get this running on Nuxt3 on storyblok? thanks
The feature would affect: (check one with "x")
Is your feature request related to a problem? Please describe. Creation of breadcrumbs with storyblok stories.
Describe the solution you'd like Would be nice to have a property with objects/parents that should be in breadcrumb according to folder structure in storyblok.
Especially if there is one story defined as root of the folder that it should be deliver in this array as parent.
Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.
Additional context Add any other context or screenshots about the feature request here.