How to put Repeated Logic at one place.

Highlighted
Shopify Partner
2 0 0

 

<div class="grid">
    <div class="grid__item medium-up--two-thirds">
      <div class="we18_navbar">
        {% assign orderHardCoded = settings.we18_collection_order | split: ',' %}
        {% for colName in orderHardCoded %}{% for collection in collections %}{% if collection.title == colName %}
            <div class="we18_navbar_dropdown">
              ---- SOME LOGIC ----
            </div>
          {% endif %}{% endfor %}{% endfor %}

          {% for collection in collections %}{% unless orderHardCoded contains collection.title %}
              <div class="we18_navbar_dropdown">
                ---- SOME LOGIC ----
              </div>
            {% endunless %}{% endfor %}
      </div>
    </div>
    <div class="grid__item medium-up--one-third"></div>
  </div>

As you can see, the "Logic Code" to display collection is repeated. Purpose of the above style is to give a particular order of collection and then loop over remaininig.

Let me know how to do it without moving code to another file. This is is already in "snippets" folder.

0 Likes