collection types

New Member
26 0 0
I think it would be helpful if we had an additional field for collections called "type" that was user definable. (eg. not a preset list of types) In my current project I have created a number of custom collections that are sample "projects" using various products (For example a bird house project that used wood, nails, and paint) I also have other custom collections for products related to "Special Occasions" or "Animals". These custom collections that are not sample projects. Then we also have smart collections like "New", "Featured", etc. So I am trying to build a top level navigation page that lists each of these collections in groups. Eg. "Project Collections", "Style Collections", "Foo Collections", ... Currently I am doing this by naming scheme. So project collection end with the word "Project". However, this is of limited use since there is no negative contains. eg. I can't do this {% if NOT collection.title contains "project" %} If I can enter a "type" variable to both smart and custom collections then I would have a lot more flexibility and could do something like. {% if collection.type == "project" %} {% if collection.type != "project" %} Cheers
0 Likes
New Member
26 0 0

Here is the solution I am using now. Take a look at the code for the last set under the heading “Other”.


<h1>Products</h1>
<h3>ArtStamps</h3>
<ul style='list-style:none;'>
{% for collection in collections %}
    {% if collection.title contains "ArtStamps" %}
        <li style="font-size:120%;line-height:160%;"><a href='/collections/{{ collection.handle }}'>{{ collection.title }}</a></li>
    {% endif %}
{% endfor %}
</ul>

<h2>Sample Projects</h2>
<ul style='list-style:none;'>
{% for collection in collections %}
    {% if collection.title contains "Project" %}
        <li style="font-size:120%;line-height:160%;"><a href='/collections/{{ collection.handle }}'>{{ collection.title }}</a></li>
    {% endif %}
{% endfor %}
</ul>

<h2>Other</h2>
<ul style='list-style:none;'>
{% for collection in collections %}
    {% if collection.title contains "Project" %}
    {% else %}
        {% if collection.title contains "ArtStamps" %}
        {% else %}
            {% if collection.title != "Frontpage" %}
                <li style="font-size:120%;line-height:160%;"><a href='/collections/{{ collection.handle }}'>{{ collection.title }}</a></li>        
            {% endif %}
        {% endif %}
    {% endif %}
{% endfor %}
</ul>

The last group is the ugliest. It has to match all collections that are not part of the first two groups and also not a function grouping like “frontpage”. As you can see below it would be a lot cleaner and more flexible if I had COLLECTION.TYPE


<h2>Other</h2>
<ul style='list-style:none;'>
{% for collection in collections %}
    {% if collection.type == "Other" %}
    <li style="font-size:120%;line-height:160%;"><a href='/collections/{{ collection.handle }}'>{{ collection.title }}</a></li>        
    {% endif %}
{% endfor %}
</ul>

0 Likes
Shopify Staff
Shopify Staff
5704 0 277

I am aware I am late into the game.

Two observations:

1. The way we often group collections is by using link lists. Under /admin/links, you click on “Add link list” to create a link list. You create one link list per group of collections, that is, one called ArtStamps, another called Sample Projects, etc. You add links to all relevant collections under each group. Then, you use Liquid to loop through the links of each link list.

2. Don’t forget to use the {% elsif %} tag. (Careful not to use {% else if %} or {% elseif %}). Your last bit of code can be more succinct:


<h2>Other</h2>
<ul style='list-style:none;'>
{% for collection in collections %}
  {% if collection.title contains "Project" %}
  {% elsif collection.title contains "ArtStamps" %}
  {% elsif collection.title != "Frontpage" %}
  <li style="font-size:120%;line-height:160%;">
    <a href='/collections/{{ collection.handle }}'>{{ collection.title }}</a>
  </li>        
  {% endif %}
{% endfor %}
</ul>
Caroline from http://11heavens.com ∴ mllegeorgesand AT gmail DOT com
0 Likes