Using Symbols with dynamic input from code

Hey!

I will describe my intentions, and please let me know if it’s possible, ír yes how, a simple demo would be very appreciated.

Let’s suppose I have a symbol with some dynamic inputs (title, description, image)

I made the layout in Builder and bind the values to appropiate fields.

Now is it possible, that I use the BuilderComponent tag inside my next.js project, and I fetch from the API my data models (with title, description, image properties) and how can I pass the values to it, like content, so that the data passed to this component, will be bound to the symbols input fields.

Thanks again!
Looking forward to hearing from you.

Hey @radikris great question!

Yes, it is possible to pass state into a symbol, or any within most of our SDKs by passing in data in the data prop, as shown here: Passing Data and Functions Down, React SDK

So, if you have a symbol that is going to be pulled into your app and used as its own stand alone section (think a header, footer, etc) this is very straight forward. All you would need to do is pass the data from the data model directly into the element, something like:

//within get Props
const data = await builder.get('someDataModel',  ...options).toPromise()|| null

...
// within component
 <BuilderComponent model="symbol" data={ ...data.data } />

now, whatever values are in the someDataModel will show inside the state of the Symbol, and you can bind to them just like you do any other binding to state.

If you want to pass data into a symbol that is being pulled into a page or section model within Builder, the setup would be a little different. Symbols within Builder all have their own state object, which is distinct from the page or section model that it is placed into. To get around that, all Symbols within Builder have an option to inherit the state from their parent page or section, found int he Advanced Options section of their Options tab:

Once you toggle this on, you can then just pass the Data Model data into the <BuilderComponent/> for the parent page, and voilá, your symbol will inherit those state values to be bound to like any other field. So within the Symbol entry itself in Builder you could get Title from state.title, get Description from state.description, etc

//within get Props
const data = await builder.get('someDataModel',  ...options).toPromise()|| null

...
// within component
 <BuilderComponent model="page" data={ ...data.data } />

Hopefully this is clear, it can be a bit esoteric until you actually write the code yourself… but try that out and see if it works for you!