Liquid, JavaScript, themes, sales channels
Hi all, I have a problem.
Basically I have blocks with background images and titles set based on the collection chosen.
When I select a collection in the 1st block, the title works fine (The title changes for only the 1st block) however the background images update for ALL blocks.
Here's a photo of the problem happening:
Here's the code:
{% for block in section.blocks %}
{% assign collection = collections[block.settings.collection] %}
{% if collection == blank %}
{% assign collection_title = 'Collection Title Here' %}
{% elsif collection != blank and block.settings.title == blank %}
{% assign collection_title = collection.title %}
{% elsif collection != blank and block.settings.title != blank %}
{% assign collection_title = block.settings.title %}
{% endif %}
{% if collection != blank and block.settings.image == blank %}
{% assign background_image = collection.image %}
{% elsif collection != blank and block.settings.image != blank %}
{% assign background_image = block.settings.image %}
{% endif %}
<div class="collection-cards-clickable">
<a href="{{ collection.url }}" class="collection-cards-link">
<div class="collection-cards"
style="background: #dedede url('{{ background_image | img_url: '600x' }}') no-repeat center center; background-size: cover;">
<h2 class="collection-card-title" style="color: {{ block.settings.color_text }}">{{ collection_title }}</h2>
<p class="collection-card-text small-paragraph-text" style="color: {{ block.settings.color_text }}">{{
block.settings.one_line_collection_description }}</p>
</div>
</a>
</div>
{% endfor %}
Where did I go wrong? Why is it duplicating?
Follow-up question: what does this mean exactly? What does the bracket mean?
Are you ready to take your business to the next level? Look no further than the latest ...
By SarahF_Shopify Apr 15, 2024We’re keeping the ball rolling to make sure you’re always ahead of the game. So buckle ...
By JasonH Apr 8, 2024Portrait of Stephen positioned next to an image of planet Earth, with the Stephen's World ...
By JasonH Mar 18, 2024