Data model for reusable components

for the children of a re-usable component, values for data binding point to the “inheritedDataModel”, which is great (see screenshot below). We can very easily connect the value for a child in the reusable component to a repeater when the reusable component is placed inside of a repeater.

image

HOWEVER, if we want to write some logic for the value of the children in the reusable component, we cannot really do that… because only Page Data and App Data are available:

It would be tremendously useful if we could also have access to “inheritedDataModel” in the logic sections.

Hi @Alex_Klein

When you open a Reusable Component for editing there is the ability to enable DataContainer for the component

  • select the component root
  • switch on the Data Container option

and you will be able to have access to the data model outside the component (for instance from a page or another component)

Regards,
Vlad

OK, when I do that (check “data container” for the reusable component), I see the option to build logic with the data model from the reusable component. So I have the option of App Data, Page Data, and “reusable component data”. How do I access a data model from some other component on the page?

only using the reusable component data

because how can you know where exactly the component is rendered before rendering it in runtime

the pattern looks like the following:

  1. you’ve got a reusable component with DataContainer enabled
  2. in the component there is another component (Text for example) which depends on data from outside
  3. instead of guessing where the data come from you can bind the Text to the reusable component data
  4. on the page where you use the reusable component you are able to modify the data model
  5. when data on the page is changes you set to the reusable component data model

does it make sense?

Right. That’s why it would be nice to include “inheritedDataModel” as an option in the logic areas for reusable components… because it is already set for the data binding of values, seems like it would be easy to have it be an explicit option in the logic building areas…

1 Like

So you mean we can modify the properties in the data model of the reusable component from outside like so

, right?

no, you need another block, and make sure you specified an id for that component instance

Great got it, thank you :pray:

Update: the way to get a reusable component to take in a data model from the “outside” is to
a) check “data container” for the top level of the reusable component, and then
b) in the parent container (i.e. the place which contains the reusable component, AKA the outside world), we can go into the logic area of the reusable component and wire up “Data Model Logic” to inject a data model that we want to use inside the reusable component. For example: