Liquid code not updating based on "alt" image

Liquid code not updating based on "alt" image

orhl1234
Shopify Partner
110 0 9

https://i1hxd88d7pu01fud-61323608109.shopifypreview.com
im trying to make a text update based on the alt text.

the alt are

red color "image_1"

black color is "image_2"

white color is "image_3" 

 

the code writes the first image's alt but not the other. why? what should i adjust for it to be updated?

 

{% assign main_image_alt = product.featured_image.alt | downcase %}
{% if main_image_alt == 'image_1' %}
  {{" image number 1 "}}
{% elsif main_image_alt == 'image_2' %}
  {{" image number 2 "}}
{% elsif main_image_alt == 'image_3' %}
  {{" image number 3 "}}
{% endif %}

 

orhl1234_0-1714833127739.png

orhl1234_1-1714833937812.png

 

 

Replies 4 (4)

BSSCommerce-B2B
Shopify Partner
1972 564 566

Hi @orhl1234 , it seems like you want to change the label "Image number 1" when you want to change the variant, right? When you render the liquid code, it executes on the server-side, and when you change the variant, the code will be re-rendered on the client-side (depending on the theme you're using), so the text not being correspondingly re-rendered. Additionally, the code snippet: {% assign main_image_alt = product.featured_image.alt | downcase %} will take the first image of the product, resulting in the text always displaying according to the first image. If you want to fix this, you can use JavaScript code.

B2B Wholesale Solution: Streamline your B2B operation with advanced features like wholesale registration forms, custom pricing.


B2B Portal, Quote, Net 30: Speed up purchasing and streamline your quotation process with advanced features like quick order, request for quote.


B2B Lock Password Protect: Easily control access to pages, products, and pricing with robust features.


BSS Commerce - Full-service eCommerce Agency I Use Shopify for 1$ in the first month now

BSSCommerce-B2B
Shopify Partner
1972 564 566

Hi @orhl1234 , it seems like you want to change the label "Image number 1" when you want to change the variant, right? When you render the liquid code, it executes on the server-side, and when you change the variant, the code will be re-rendered on the client-side (depending on the theme you're using), so the text not being correspondingly re-rendered. Additionally, the code snippet: {% assign main_image_alt = product.featured_image.alt | downcase %} will take the first image of the product, resulting in the text always displaying according to the first image. If you want to fix this, you can use JavaScript code.

 

B2B Wholesale Solution: Streamline your B2B operation with advanced features like wholesale registration forms, custom pricing.


B2B Portal, Quote, Net 30: Speed up purchasing and streamline your quotation process with advanced features like quick order, request for quote.


B2B Lock Password Protect: Easily control access to pages, products, and pricing with robust features.


BSS Commerce - Full-service eCommerce Agency I Use Shopify for 1$ in the first month now

orhl1234
Shopify Partner
110 0 9

hi!
could you maybe help me with that?

BSSCommerce-B2B
Shopify Partner
1972 564 566

Hi!

Can you kindly share your store link (with the password, if any), name theme with us? We will check it and suggest you a solution if possible.

B2B Wholesale Solution: Streamline your B2B operation with advanced features like wholesale registration forms, custom pricing.


B2B Portal, Quote, Net 30: Speed up purchasing and streamline your quotation process with advanced features like quick order, request for quote.


B2B Lock Password Protect: Easily control access to pages, products, and pricing with robust features.


BSS Commerce - Full-service eCommerce Agency I Use Shopify for 1$ in the first month now