How to get widget's page programmatically

149
0
03-28-2024 06:44 AM
WalaZargouni
New Contributor II

Hello, in experience builder 1.14 i need a way to figure out the page of a given widget or a way to figure out what widgets are on page x and of course programmatically.
I tried this piece of code where i do the link between widgets and pages based on the layout property, can someone confirm this or give some advices ?

    const widgetId = getWidgetId() //get the id of the given widget
    const appConfig = getAppStore().getState().appConfig
    const widgets = appConfig.widgets
    const widgetLayoutId = widgets[widgetId].parent?.LARGE?.[0].layoutId
    const pages = appConfig.pages
    const pagesKeys = Object.keys(pages)
    let widgetPageId = ''
    pagesKeys.forEach(key => {
      if (pages[key].layout.LARGE === widgetLayoutId) {
        widgetPageId = key
      }
    })
Tags (2)
0 Kudos
0 Replies