I’m currently developing a Shopify app and have encountered a challenge that I’m hoping to get some insights on.
Objective: I aim to dynamically fetch entries of a specific metaobject type and present these entries to the user as a selectable list within the theme customizer. This would be part of the functionality where a user can add a block from my app to their store’s theme.
Issue: As I understand, Shopify’s Liquid language does not allow for dynamic fetching of metaobject entries directly within the theme customizer. My goal is to enable users to select from existing metaobject entries (which are instances of a metaobject created by my app) when they are adding a block related to my app on their storefront.
Current Approach:
- People can successfully create a metaobject and can create entries thru my app.
- I’m considering the potential of using Shopify’s Storefront API to fetch these entries dynamically, but I’m not sure how to integrate this into the theme customizer’s options.
- The documentation suggests that this may not be a straightforward task and might require a workaround.
Question: Has anyone in the community successfully implemented a similar feature, or can someone suggest potential methods for achieving this? Any examples or guidance would be greatly appreciated.
Here is what I’ve tried so far:
- I looked into using Liquid code to pull in metaobject entries but hit the limitation of static rendering.
- I considered using an AJAX call from the theme customizer to the Storefront API, but I’m unsure how to integrate this into the block settings for the user to make a selection.
Specifics:
- The metaobject is called “Timer”.
- The type is “app–XXXXXXX–timer”.
- Users should be able to select a “Timer” when they add a block from my app to their page.
Ideas:
- Perhaps there is a way to use a combination of Liquid and JavaScript to fetch the data when the theme editor loads?
- Maybe an app proxy could serve as a bridge for the data?
I’m open to creative solutions and would love to hear if anyone has tackled a similar challenge. Thank you in advance for your help and ideas!