Can ERB be used in form.yml?

I’m developing an interactive application and would like to include a select list in the form.yml. However, instead of hardcoding the options in the dropdown, I would like them to be dynamically generated from a system command. Here is what I have tried (which does not work):

  project_group:
    label: "Project group"
    widget: "select"
    options:
    <%= `get_groups command`.split('\n').each do |group| %>
      - <%= group %>
    <% end %>

Is this sort of thing supported? If so, am I doing something wrong? My guess is that since form.yml is not referenced as ending in .erb, it is not rendered by the templating engine. Is that assumption correct?

Thanks,
Nick

Your assumption is correct. You need to rename form.yml to form.yml.erb in order for the erb to be executed.

1 Like

You can also use erb in submit.yml - rename it to submit.yml.erb. And any file in the template directory, if it has .erb appended to it, that will get rendered and then a new file added to the copied template with the same filename sans the .erb extension

1 Like

Thank you, this is great. I was already using submit.yml.erb, but I didn’t know that I could force ERB to render any file in the application folder just by adding the extension .erb. Everything is working as expected now.

Nick

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.