Home
Support Forums

Create selectable list in CMS to select from data file

I’m using 11ty to build a multi-lingual site, currently stuck at how I could allow authors to select a Topic/Category from a list of values in a data file.

The field code I’ve tried last:

// The topic list
const topics = {
  i18n: true,
  label: "Select a Topic",
  name: "topics",
  widget: "select",
  file: "site/_data/topics.json",
  multiple: false,
... ?
};

export default topics;

The topics.json:

{
    "topics": [
      "Lifestyle",
      "Business",
      "Health",
      "Food",
      "Love & Relationships",
      "Tech",
      "Entertainment",
      "Shopping",
      "Home & Privacy",
      "Family & Pets"
    ]
  }

Now this list format json, and also the widget type are not set in stone.
I can use whatever proves to be working :smile:

The end result should be, that writers have a select field in their UI where they can select 1 topic for the content piece they’re writing.

The topics list is also going to be used to display Categories on the website, and then display entries for each topic…

And I need to make it work with internationalization i18n.

Is this doable, and if so: how? pretty please :slight_smile:

actually, as so often. I found a good solution after posting ahaha.

For the record, and in case someone has a better solution, I just import the json file in my js module and use the array as options.

1 Like

Hey there, @madsem :wave:

Thanks so much for coming back and sharing your solution with us! It will be beneficial for future Forums members who encounter something similar :slight_smile:

1 Like