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:
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: https://github.com/SYMBIO/datocms-plugin-tree-url. Feel free to fork it.
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 https://example.com/ the slugs of the parent pages were available dynamically. For instance, https://example.com/wealth would be in the grey area, if the wealth page were the parent of investment.
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.