Data binding to content item custom fields

Is there a way to create a data binding directly to a content item custom field?

Currently, I’m extracting the custom field values from the downloaded content item JSON on my back end, feeding it back to the content item’s state using the data prop, then binding on state.

I’d like to cut out the middleman and just bind directly to my fields.

Possible?

Hey @ersin !

This is indeed possible, though does require a bit of code in the binding / wherever you intend to use this data.

Basically, within custom JS I would recommend either setting the value to state by putting:

state.whatever = context.builderContent.data.whatever

Or, in your data binding you can access directly with

context.builderContent.data.whatever

I think there is a world where we eventually add the ability for a custom field to be added to state as a flag on the field itself, but for now this is the best practice route.

If you think that is a use case you will use a lot, I recommend submitting a feature request to our ideas board at ideas.builder.io !

Hope this helps !

Thanks for the tip, Tim! And I added it to ideas: Allow direct data binding to custom content fields | Builder.io Ideas

1 Like