How do I convert white spaces in entity names to underscores and not hyphens during folder creation?

If an entity has white space characters in its name, by default Toolkit will replace these characters with hyphens when creating folders and files.

It’s not uncommon for us to get asked if it’s possible to replace white space characters with underscores instead. To which the answer is yes it’s possible but not normally advisable.

The reason for this is that we use the _ character as a separator between template keys.
As an example, if we had ...{asset}_{task}... in a template path, and if we know that the asset and task values can’t contain the _ character then we can parse from a given path ( ...my-asset_a-task... ) the template key value pairs so that we get:

{ "asset": "my-asset",
  "task" : "my-task"}

If we allowed _ then you would have a path that looks like ...my_asset_a_task... and then it’s basically impossible to know where one starts and the other ends without knowing the values up front.

You could change your templates so that the characters separating your template keys are not _ and then make sure that template keys don’t allow the use of that separator.

But to answer the question directly, the values allowed in templates can be controlled via the filter_by key which you would set on your key in the templates.yml file:

The schema folders themselves are handled slightly differently through the core hook process_folder_name.py:

It’s a case of taking over the hook and modifying the methods behaviour to allow for the _ character.