Hierarchical collections

DatoCMS already allows records to be sorted manually with drag & drop. The next logical step would be to allow the creation of a "tree" of records.

2 people like this idea

Yes. Ideally, this could be used for modelling navigation;  perhaps optionally linkable to a particular model and field. e.g. link to "Page" model and the "Slug" field thereof? This is more complex, as it would mean the Tree would be determining the value of a field on those records, like a computed property...

Well, you could just create a tree model called "Navigation", with a "Label" String field and Link field pointing to the page, right? 

Right, but what I'm thinking is that the Tree field could actually affect a field on the Page record—so if I take a Page record with a slug of 'foo' and nest it in my Tree model under a label of 'bar', that record would now have a permalink field with a value of 'bar/foo'. But maybe this is really a larger topic, as essentially it's about routing, and one would also want to be able to implement rule-based routing e.g.  for "Post" types, and also right now "routing" as such is rather done in the 'dump' script process... I'm not sure how one would keep all those things in sync

Uh, I get it now. Yes, we'd rather keep routing logic outside of DatoCMS, every website has its own different strategies for that :)

Agreed. So I guess my suggestion would be that this field type (whether it be called Tree/Hierarchy/Structure/whatever), be something I could add to the global site settings, optionally oriented to a specific content type e.g. Pages, which would allow me to hierarchically order and structure those items with labels, and those labels be linked to the records by their IDs.  

That should result in an object I could parse in the dump script, which would allow me to control how/where HTML files are output (i.e. routing, if it's a static-file app), or how SPA routes are defined (if it's a client-side app), and also something I could use to structure navigation elements.

Implemented! You can now configure a model collection to be organized as a tree:


In the Content tab of your administrative area you will then be able to drag & drop records:


Both JS and Ruby clients have been updated and expose the following methods:


module.exports = (dato, root, i18n) => {
  const category = dato.categories[0];

  category.parent; // returns the parent record
  category.children; // returns the children records as an array


2 people like this
Login to post a comment