Showing collection description only in specific collections. DEBUT THEME

Shopify Partner
42 1 2

Hi! So once I modified the code to not show the collection description, I wanted to write descriptions for SEO purposes but didn't want to it to be displayed in my store. What I did was comment the lines of the code on product-template.liquid like this:

 {% if collection.description != blank %}
        <div class="rte collection-description page-width">
         {% comment %} 
          {{ collection.description }}
         {% endcomment %}

        </div>
      {% endif %}
    {% else %}
      <div class="page-width">
        <div class="section-header text-center">
          <h1>{{ collection.title }}</h1>
           {% comment %} 
          {% if collection.description != blank %}
            <div class="rte">
              {{ collection.description }}
            </div>
          {% endif %}
          {% endcomment %}
         
        </div>
      </div>
    {% endif %}
   

Now I want to change the code a bit to display the description in certain collections.... I tried using an if statement based on the collection title and also on the collection handles with no luck. I also tried with an unless statement, something like this:

 {% if collection.description != blank %} 
<div class="rte collection-description page-width">
{{ collection.description }}
{% unless collection.handle != "collection1" or "collection2" %}
{% endunless %}
</div> {% endif %}

But it didn't seemed to work. I'm on the right track for doing this? I'm a bit new to coding, but I believe I can manage with a little bit of help.

0 Likes
Shopify Partner
1142 93 139

Hi @Jose13

Try this 

all is collection handle you want to show a collection description

{% if collection.handle == 'all' %}
{% if collection.description != blank %} <div class="rte collection-description page-width"> {{ collection.description }} </div> {% endif %}
{% endif %}

 

Thanks & Regards
Perennial Solution

Problem Solved?✔️Like and Accept the solution that can help others.
Need any help with theme customization or design? Hire us
Email: infoperennialsolution@gmail.com
Skype: infoperennialsolution
0 Likes
Shopify Partner
42 1 2

Hi! I tried this but didn't work! Let me paste the whole code of my collection-template.liquid as I currently have. I tried your solution and a few variations with no luck. I also tried using collection title and the 'contains' but nothing happens.


{% case section.settings.grid %}
  {% when 2 %}
    {%- assign max_height = 530 -%}
  {% when 3 %}
    {%- assign max_height = 345 -%}
  {% when 4 %}
    {%- assign max_height = 250 -%}
  {% when 5 %}
    {%- assign max_height = 195 -%}
{% endcase %}

{% if section.settings.layout == 'grid' %}
  {%- assign limit = section.settings.grid | times: section.settings.rows -%}
{% else %}
  {%- assign limit = 16 -%}
{% endif %}

{% paginate collection.products by limit %}


<div data-section-id="{{ section.id }}" data-section-type="collection-template">
  <header class="collection-header">
    
    {% if section.settings.show_collection_image and collection.image %}
      <div class="collection-hero">
        <div class="collection-hero__image ratio-container lazyload js"
             data-bgset="{% include 'bgset', image: collection.image %}"
             data-sizes="auto"
             data-parent-fit="cover"
             style="background-image: url('{{ collection.image | img_url: '300x300' }});"></div>
        
        <noscript>
          <div class="collection-hero__image" style="background-image: url({{ collection.image | img_url: '2048x600' }});"></div>
        </noscript>
        <div class="collection-hero__title-wrapper">
          
          <h1 class="collection-hero__title page-width">{{ collection.title }}</h1>
        </div>
      </div>

      {% if collection.description != blank %}
        <div class="rte collection-description page-width">
         {% comment %} Collection description disappears
          {{ collection.description }}
         {% endcomment %}

        </div>
      {% endif %}
    {% else %}
      <div class="page-width">
        <div class="section-header text-center">
          <h1>{{ collection.title }}</h1>
           {% comment %} Collection description disappears
          {% if collection.description != blank %}
            <div class="rte">
              {{ collection.description }}
            </div>
          {% endif %}
          {% endcomment %}
         
        </div>
      </div>
    {% endif %}
   

    {% if section.settings.tags_enable or section.settings.sort_enable %}
      <div class="filters-toolbar-wrapper">
        <div class="page-width">
          <div class="filters-toolbar">
            {% if section.settings.tags_enable %}
              <div class="filters-toolbar__item">
                <label for="SortTags" class="label--hidden">{{ 'collections.filters.title_tags' | t }}</label>
                <select class="filters-toolbar__input filters-toolbar__input--filter hidden" name="SortTags" id="SortTags">
                  {% if current_tags %}
                    {% if collection.handle %}
                      <option value="/collections/{{ collection.handle }}">{{ 'collections.filters.all_tags' | t }}</option>
                    {% elsif collection.current_type %}
                      <option value="{{ collection.current_type | url_for_type }}">{{ 'collections.filters.all_tags' | t }}</option>
                    {% elsif collection.current_vendor %}
                      <option value="{{ collection.current_vendor | url_for_vendor }}">{{ 'collections.filters.all_tags' | t }}</option>
                    {% endif %}
                  {% else %}
                    {% if current_tags contains tag %}
                      <option value="">{{ 'collections.filters.all_tags' | t }}</option>
                    {% else %}
                      <option value="">{{ 'collections.filters.title_tags' | t }}</option>
                    {% endif %}
                  {% endif %}
                  {% for tag in collection.all_tags %}
                    <option value="/collections/{% if collection.handle != blank %}{{ collection.handle }}{% else %}all{% endif %}/{{ tag | handleize }}"{% if current_tags contains tag %} selected="selected"{% endif %}>{{ tag }}</option>
                  {% endfor %}
                </select>
              </div>
            {% endif %}

            <div class="filters-toolbar__item filters-toolbar__item--count">
              <span class="filters-toolbar__product-count">{{ 'collections.general.items_with_count' | t: count: collection.products_count }}</span>
            </div>

            {% if section.settings.sort_enable %}
              <div class="filters-toolbar__item text-right">
                {%- assign sort_by = collection.sort_by | default: collection.default_sort_by -%}
                <label for="SortBy" class="label--hidden">{{ 'collections.sorting.title' | t }}</label>
                <select name="SortBy" id="SortBy" class="filters-toolbar__input filters-toolbar__input--sort hidden">
                  {% if sort_by == collection.default_sort_by %}
                    <option value="title-ascending" selected="selected">{{ 'collections.sorting.title' | t }}</option>
                    {% if collection.default_sort_by != 'manual' %}
                      <option value="manual"{% if sort_by == "manual" %} selected="selected"{% endif %}>{{ 'collections.sorting.featured' | t }}</option>
                    {% endif %}
                    {% if collection.default_sort_by != 'best-selling' %}
                      <option value="best-selling"{% if sort_by == "best-selling" %} selected="selected"{% endif %}>{{ 'collections.sorting.best_selling' | t }}</option>
                    {% endif %}
                    {% if collection.default_sort_by != 'title-ascending' %}
                      <option value="title-ascending"{% if sort_by == "title-ascending"  %}selected="selected"{% endif %}>{{ 'collections.sorting.az' | t }}</option>
                    {% endif %}
                    {% if collection.default_sort_by != 'title-descending' %}
                      <option value="title-descending"{% if sort_by == "title-descending" %} selected="selected"{% endif %}>{{ 'collections.sorting.za' | t }}</option>
                    {% endif %}
                    {% if collection.default_sort_by != 'price-ascending' %}
                      <option value="price-ascending"{% if sort_by == "price-ascending" %} selected="selected"{% endif %}>{{ 'collections.sorting.price_ascending' | t }}</option>
                    {% endif %}
                    {% if collection.default_sort_by != 'price-descending' %}
                      <option value="price-descending"{% if sort_by == "price-descending" %} selected="selected"{% endif %}>{{ 'collections.sorting.price_descending' | t }}</option>
                    {% endif %}
                    {% if collection.default_sort_by != 'created-descending' %}
                      <option value="created-descending"{% if sort_by == "created-descending" %} selected="selected"{% endif %}>{{ 'collections.sorting.date_descending' | t }}</option>
                    {% endif %}
                    {% if collection.default_sort_by != 'created-ascending' %}
                      <option value="created-ascending"{% if sort_by == "created-ascending" %} selected="selected"{% endif %}>{{ 'collections.sorting.date_ascending' | t }}</option>
                    {% endif %}
                  {% else %}
                    <option value="manual"{% if sort_by == "manual" %} selected="selected"{% endif %}>{{ 'collections.sorting.featured' | t }}</option>
                    <option value="best-selling"{% if sort_by == "best-selling" %} selected="selected"{% endif %}>{{ 'collections.sorting.best_selling' | t }}</option>
                    <option value="title-ascending"{% if sort_by == "title-ascending"  %}selected="selected"{% endif %}>{{ 'collections.sorting.az' | t }}</option>
                    <option value="title-descending"{% if sort_by == "title-descending" %} selected="selected"{% endif %}>{{ 'collections.sorting.za' | t }}</option>
                    <option value="price-ascending"{% if sort_by == "price-ascending" %} selected="selected"{% endif %}>{{ 'collections.sorting.price_ascending' | t }}</option>
                    <option value="price-descending"{% if sort_by == "price-descending" %} selected="selected"{% endif %}>{{ 'collections.sorting.price_descending' | t }}</option>
                    <option value="created-descending"{% if sort_by == "created-descending" %} selected="selected"{% endif %}>{{ 'collections.sorting.date_descending' | t }}</option>
                    <option value="created-ascending"{% if sort_by == "created-ascending" %} selected="selected"{% endif %}>{{ 'collections.sorting.date_ascending' | t }}</option>
                  {% endif %}
                </select>
                <input id="DefaultSortBy" type="hidden" value="{{ collection.default_sort_by }}">
              </div>
            {% endif %}
          </div>
        </div>
      </div>
    {% endif %}
  </header>

  <div class="page-width" id="Collection">
    {% if section.settings.layout == 'grid' %}
      {% case section.settings.grid %}
      {% when 2 %}
        {%- assign grid_item_width = 'medium-up--one-half' -%}
      {% when 3 %}
        {%- assign grid_item_width = 'small--one-half medium-up--one-third' -%}
      {% when 4 %}
        {%- assign grid_item_width = 'small--one-half medium-up--one-quarter' -%}
      {% when 5 %}
        {%- assign grid_item_width = 'small--one-half medium-up--one-fifth' -%}
      {% endcase %}

      <div class="grid grid--uniform{% if collection.products_count > 0 %} grid--view-items{% endif %}">
        {% for product in collection.products %}
          <div class="grid__item grid__item--{{section.id}} {{ grid_item_width }}">
            {% include 'product-card-grid', max_height: max_height %}
          </div>
        {% else %}
          {% comment %}
          Add default products to help with onboarding for collections/all only.

          The onboarding styles and products are only loaded if the
          store has no products.
          {% endcomment %}
          {% if collection.handle == 'all' and collection.all_vendors.size == 0 and collection.all_types.size == 0 %}
            <div class="grid__item">
              <div class="grid grid--uniform">
                {% for i in (1..limit) %}
                  <div class="grid__item {{ grid_item_width }}">
                    <div class="grid-view-item">
                      <a href="#" class="grid-view-item__link">
                        <div class="grid-view-item__image">
                            {% capture the_snippet_fave_icon %}{% include 'ssw-widget-faveicon' with product.id %}{% endcapture %}
                            {% unless the_snippet_fave_icon contains 'Liquid error' %}
                            {{ the_snippet_fave_icon }}
                            {% endunless %}
                          {% capture current %}{% cycle 1, 2, 3, 4, 5, 6 %}{% endcapture %}
                          {{ 'product-' | append: current | placeholder_svg_tag: 'placeholder-svg' }}
                        </div>
                        <div class="h4 grid-view-item__title">{{ 'homepage.onboarding.product_title' | t }}</div>
                        <div class="grid-view-item__meta">
                          <span class="product-price__price">$19.99</span>
                        </div>
                      </a>
                    </div>
                  </div>
                {% endfor %}
              </div>
            </div>
          {% else %}
            {%- assign is_empty_collection = true -%}
          {% endif %}
        {% endfor %}
      </div>
    {% else %}
      <ul class="list-view-items">
        {% for product in collection.products %}
          <li class="list-view-item">
            <a href="{{ product.url | within: collection }}" class="list-view-item__link">
              {% include 'product-card-list', product: product %}
            </a>
          </li>
        {% else %}

          {% comment %}
          Add default products to help with onboarding for collections/all only.

          The onboarding styles and products are only loaded if the
          store has no products.
          {% endcomment %}
          {% if collection.handle == 'all' and collection.all_vendors.size == 0 and collection.all_types.size == 0%}
            {% for i in (1..4) %}
              <li class="list-view-item">
                <a href="#" class="list-view-item__link">
                  <div class="list-view-item__image-column">
                    <div class="list-view-item__image-wrapper">
                      <div class="list-view-item__image">
                        {%- assign placeholder = 'placeholder-product-' | append: i -%}
                        {% include placeholder %}
                      </div>
                    </div>
                  </div>

                  <div class="list-view-item__title-column">
                    <div class="list-view-item__title">{{ 'homepage.onboarding.product_title' | t }}</div>
                  </div>

                  <div class="list-view-item__price-column">
                    <span class="product-price__price">$19.99</span>
                  </div>
                </a>
              </li>
            {% endfor %}
          {% else %}
            {%- assign is_empty_collection = true -%}
          {% endif %}
        {% endfor %}
      </ul>
    {% endif %}

    {% if is_empty_collection %}
      <div class="grid__item small--text-center">
        <p class="text-center">{{ 'collections.general.no_matches' | t }}</p>
      </div>
    {% endif %}

    {% if paginate.pages > 1 %}
      {% include 'pagination' %}
    {% endif %}
  </div>
</div>

{% endpaginate %}
 
{% schema %}
  {
    "name": {
      "en": "Collection pages",
      "de": "Kategorie-Seiten",
      "fr": "Pages de collections"
    },
    "settings": [
      {
        "type": "select",
        "id": "layout",
        "label": {
          "en": "Layout",
          "de": "Layout",
          "fr": "Mise en page"
        },
        "default": "grid",
        "options": [
          {
            "value": "grid",
            "label": {
              "en": "Grid",
              "de": "Raster",
              "fr": "Grille"
            }
          },
          {
            "value": "list",
            "label": {
              "en": "List",
              "de": "Liste",
              "fr": "Liste"
            }
          }
        ]
      },
      {
        "type": "range",
        "id": "grid",
        "label": {
          "en": "Products per row (grid only)",
          "de": "Produkte per Reihe (nur Raster)",
          "fr": "Produits par rangée (grille uniquement)"
        },
        "default": 4,
        "min": 2,
        "max": 5,
        "step": 1
      },
      {
        "type": "range",
        "id": "rows",
        "label": {
          "en": "Rows per page (grid only)",
          "de": "Reihen per Seite (nur Raster)",
          "fr": "Rangées par page (grille uniquement)"
        },
        "default": 2,
        "min": 2,
        "max": 8,
        "step": 1
      },
      {
        "type": "checkbox",
        "id": "show_collection_image",
        "label": {
          "en": "Show collection image",
          "de": "Kategorie-Foto anzeigen",
          "fr": "Afficher l'image de la collection"
        },
        "default": true
      },
      {
        "type": "checkbox",
        "id": "show_vendor",
        "label": {
          "en": "Show product vendors",
          "de": "Produkt-Lieferanten anzeigen",
          "fr": "Afficher les vendeurs"
        },
        "default": false
      },
      {
        "type": "checkbox",
        "id": "sort_enable",
        "label": {
          "en": "Enable sorting",
          "de": "Sortieren erlauben",
          "fr": "Activer le tri"
        },
        "default": true
      },
      {
        "type": "checkbox",
        "id": "tags_enable",
        "label": {
          "en": "Enable tag filtering",
          "de": "Tag-Filtern erlauben",
          "fr": "Activer le filtrage par balises"
        },
        "default": true
      }
    ]
  }
{% endschema %}
0 Likes