Collection Image Duplicating?

dwightco
Excursionist
18 0 2

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:

dwightco_0-1614870447839.png

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?

{% assign collection = collections[block.settings.collection%}
0 Likes