Computed Widget?

Using Gatsby, the createPages function requires a path value to send to the page graphql query on generation.

In Netlify CMS, I could ask the user to manually enter this value into a path parameter, but I’d like to enforce some path rules by forcing generation of this variable to be saved into the markdown file.

Is there a way to create a computed widget, so that I can create a custom slug like variable, which allows us to generate the path based on another user input field?

Thanks!

A widget can provide a custom value, but it doesn’t currently have access to the other field values. If you don’t need anything dynamic, like processing the other field values, you could use field values in your path field’s default value via template string:

default: “some-string-{{title}}-{{other_field}}”

Then if you set the widget to “hidden”, you get an invisible path.

That said, if you do need dynamic things, like maybe generating a unique id, open an issue on the CMS repo for passing the current entry to each widget.

Thanks for the response erquhart!
We tried that default, but it didn’t work. Does order of the fields matter for that at all? Is there any documentation besides the slug field for that?

Thanks!

So sorry I do not know what I was thinking there - replacement variables are not available for default field values! Here’s the issue tracking it: https://github.com/netlify/netlify-cms/issues/1975.

For now, I’ve heard of folks creating dynamic paths in the gatsby site rather than trying to do it through the CMS. Might be worth reaching out in the Gatsby community to see if anyone has insight.