Store specific files in app block

Solved

Store specific files in app block

somen-1001
Shopify Partner
5 0 0

I'm trying to migrate my app to theme app extensions as the assets api are going to be deprecated. Currently I embed different files for different stores based on their configuration preferences. Is there any way to perform the same in the app block where my app extension can have different assets for different clients?

Accepted Solution (1)

Moeed
Shopify Partner
5353 1448 1734

This is an accepted solution.

Hey @somen-1001 

Yes, you can achieve the same functionality of embedding different files for different stores using the app block and app extensions in Shopify's theme app extensions approach. Here's how you can handle different assets for different clients:

 

  • Define Configuration Options: In your app extension, you can define configuration options that allow clients to specify their preferences. For example, you can add a configuration option to specify a custom asset file or a file URL for each client.

  • Store Configuration: Store the configuration preferences set by each client in your app's database or a configuration file associated with each store.

  • Conditional Asset Loading: Within your app block's Liquid code, you can use conditional statements to load the appropriate asset based on the client's configuration preference. For example, you can check the client's configuration option and dynamically load the specified asset file or URL.

{% if shop.metafields.your_app_namespace.custom_asset %}
  <link rel="stylesheet" href="{{ shop.metafields.your_app_namespace.custom_asset }}">
{% else %}
  <link rel="stylesheet" href="default-asset.css">
{% endif %}

In the above example, the code checks if the custom_asset configuration option is set for the specific store (shop). If it exists, it loads the specified asset file. Otherwise, it falls back to a default asset file (default-asset.css).

 

  • Update Configuration: If the client wants to change the asset file or URL, you can provide an interface within your app for them to update the configuration preferences. This can be a settings page or a configuration form.

By utilizing the app block and app extensions approach, you can dynamically load different assets for different clients based on their configuration preferences. This allows you to provide customized experiences for each client without relying on the deprecated assets API.

 

Remember to handle cases where the asset file or URL specified by the client is no longer accessible or has changed.

 

If I managed to help you then, don't forget to Like it and Mark it as Solution!

 

Best Regards,
Moeed

- Need a Shopify Specialist? Chat on WhatsApp

- Custom Design | Advanced Coding | Store Modifications


View solution in original post

Reply 1 (1)

Moeed
Shopify Partner
5353 1448 1734

This is an accepted solution.

Hey @somen-1001 

Yes, you can achieve the same functionality of embedding different files for different stores using the app block and app extensions in Shopify's theme app extensions approach. Here's how you can handle different assets for different clients:

 

  • Define Configuration Options: In your app extension, you can define configuration options that allow clients to specify their preferences. For example, you can add a configuration option to specify a custom asset file or a file URL for each client.

  • Store Configuration: Store the configuration preferences set by each client in your app's database or a configuration file associated with each store.

  • Conditional Asset Loading: Within your app block's Liquid code, you can use conditional statements to load the appropriate asset based on the client's configuration preference. For example, you can check the client's configuration option and dynamically load the specified asset file or URL.

{% if shop.metafields.your_app_namespace.custom_asset %}
  <link rel="stylesheet" href="{{ shop.metafields.your_app_namespace.custom_asset }}">
{% else %}
  <link rel="stylesheet" href="default-asset.css">
{% endif %}

In the above example, the code checks if the custom_asset configuration option is set for the specific store (shop). If it exists, it loads the specified asset file. Otherwise, it falls back to a default asset file (default-asset.css).

 

  • Update Configuration: If the client wants to change the asset file or URL, you can provide an interface within your app for them to update the configuration preferences. This can be a settings page or a configuration form.

By utilizing the app block and app extensions approach, you can dynamically load different assets for different clients based on their configuration preferences. This allows you to provide customized experiences for each client without relying on the deprecated assets API.

 

Remember to handle cases where the asset file or URL specified by the client is no longer accessible or has changed.

 

If I managed to help you then, don't forget to Like it and Mark it as Solution!

 

Best Regards,
Moeed

- Need a Shopify Specialist? Chat on WhatsApp

- Custom Design | Advanced Coding | Store Modifications