All things Shopify and commerce
Does anyone know how to get more blocks in Shopify Story theme? I am trying to get more selected variant such as changing product colour when selecting different colour and also changing photo of different size of product when selecting different size
Hi @yang1
I notice that you want to display variant-specific content in the Story theme, such as updating images when a customer selects a different color or size. Shopify’s default variant selector doesn’t dynamically update blocks (like images, text, or other sections) based on variant selection, but you can achieve this by modifying the theme’s code.
Here’s how to do it:
Shopify’s built-in variant media feature automatically changes images when a variant is selected. Make sure your product media settings are correctly linked:
The Story theme doesn’t provide variant-specific blocks out of the box, so you’ll need to modify the product template. Here’s how to do it:
{
"type": "variant_block",
"settings": [
{
"id": "variant_condition",
"type": "text",
"label": "Variant Condition"
}
]
}
This allows Shopify’s theme editor to recognize the block.
{% for variant in product.variants %}
<div class="variant-block" data-variant-id="{{ variant.id }}" style="display: none;">
{% if variant.title contains "Red" %}
<p>This is a red variant block.</p>
<img src="{{ variant.featured_image | img_url: 'large' }}" alt="{{ variant.title }}">
{% endif %}
</div>
{% endfor %}
Then, add this JavaScript inside theme.js (or custom.js) to make the blocks update dynamically:
document.addEventListener("DOMContentLoaded", function() {
let variantSelector = document.querySelector('select[name="id"]');
if (variantSelector) {
variantSelector.addEventListener("change", function() {
let selectedVariant = this.value;
document.querySelectorAll(".variant-block").forEach(block => {
block.style.display = block.getAttribute("data-variant-id") === selectedVariant ? "block" : "none";
});
});
}
});
If you prefer not to edit code, you can use an app like Variant Option Product Options or Infinite Options from the Shopify App Store. These apps let you control variant-specific blocks without coding.
This method should work for adding more variant-specific blocks to your Story theme. If you’re facing issues or need more customization, just let me know and I’ll do my best to help!
Best regards,
Daisy
Hey Community 👋 Did you know that March 15th is National Everything You Think Is W...
By JasonH Apr 1, 2025Discover how to increase the efficiency of commerce operations with Shopify Academy's l...
By Jacqui Mar 26, 2025Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025