Slug should represent structure in tree collections

When using a slug in a tree-like collection the slug should represent the structure.

I think, if a slug field is added to a model in a tree collection, it makes the most sense to let the slug represent the collection. This way you are able to let editors nest pages and get the content structure they expect from the CMS.

I know Dato is also used for many other cases than websites, but I also think when slugs are used they are mainly targeted websites.

@mads our approach here is to use the slug as an identifier only for the record, not for the entire tree. As you might want to reorder your structure and change your URL accordingly.

What you can do to help your editors is to change what you present in the interface here:

what do you think?

We’ve made a plugin, which builds URL from the slug of the parent record and the current record ({parent_slug}/{current_slug}). You can find it here: Feel free to fork it.

1 Like

@dev3 I can’t find your plugin in the plugin repository. Is it published to npm?

Is it possible for you to make it a public plugin so it can be installed from Dato?

I’d like to see an option for the slug field to prepend slugs of the parent pages to the slug of the current page.

If the pages are re-organised, the slug structure would change too.

@mat_jack1 Have there been any changes since this was last discussed? What would be a recommended way to construct slugs from the tree structure?

1 Like

hey @max.c this has not changed recently, but to me you should fetch all the slugs locally and build your slug structure on your frontend, what do you think?

Hey @mat_jack1 , that’s great, but then the slug field in the UI would not show the real URL structure anymore. On the screenshot I attached it would be great if after the slugs of the parent pages were available dynamically. For instance, would be in the grey area, if the wealth page were the parent of investment.

1 Like

This would be awesome and is how most traditional CMS work

hey @max.c @myles you can customize how the preview URL looks like, you need to customize the presentation settings here:

Let me know if you expected something different

1 Like

@mat_jack1 I don’t think the url prefix is dynamic. For example it won’t change the pathname based on parent posts

The prefix is static yes, it doesn’t solve the issue for trees actually. It can help, but it doesn’t do everything you need.

The only solution would be to use a plugin that fetches the full URL from your frontend, so that you get maximum flexibility and correct information on the full URL. I know it’s a bit convoluted, but the routing of your frontend is something that we don’t manage, so it would be a bit strange to show the full structure when it could be handled differently in the frontend.