I have a field I use in a custom module that applies a style to a button - it’s a “Choice” field with many different options.
I want to use that button in lots of other different custom modules but I don’t want to have to keep on repeating the entry of all the options when creating the field.
Is there a away of holding that field “centrally” and then dropping it in to custom modules - a global field if you like? I’m assuming we can’t have modules within modules still…
Unfortunately, this isn’t possible since you can’t nest a custom module inside another custom module and, there’s no real good way to create a global dictionary that would be available to all of your custom modules. The timing of the loading of the custom modules vs. the timing of setting the dictionary values would be hit or miss.
This is very advanced javascript and their method isn’t clearly documented so I do not blame you. In cloudcannon, I would just add my field configs to a global config file to be inherited by all of my module but the root fields.json is just designated for the theme (eg adding colors, fonts, and meta). Here’s what I did and I would hope that @alyssamwilie has some additional insight to these rest of the owl docs hubspot has: Requirements
As a developer, I want to create a global field group that I can reference across several modules in the fields.json file of each module.
Steps to Recreate
I created a subdirectory in my theme folder named global fields (my-theme/global-fields)
I added a fields.js file to the root of my global-fields folder and added the code from the Common fields docs.
I cd into my theme directory (cd my-theme) and ran the following command:
I expected to be able to refence the fields.json generated by the hs cms convert-fields command in mutliple modules.
What Happened
No docs on how to systematically set common fields for modules. Just generating an output file per module which seems inefficient.
A fields.output.json was generated. It appeared to be just like the fields.json I have in all of my modules. However, there is no clear method of importing that fields.output.json outside of copying the json and adding it to each of my modules. I’m also curious as to why I have to write a separate javascript in order to generate JSON that I can easily write myself without the complexities of module.exports.
Don’t know if you build locally using the HubSpot CLI but HubSpot actually has public beta out right now for writing fields.json using Javascript that includes the ability to create a fields.js of common fields that can be imported and used across multiple modules: