title: How to sort product tags based on another array in Shopify liquid
body: <p>I have an issue where I need to display tags in a specific order, based on the first part of the tag.  For example, I have a list of potential product tags:</p>
  
  <pre><code>category_electronics
  size_large 
  color_black 
  color_brown 
  weight_10
  </code></pre>
  
  <p>And I need them to sort based on a pre-set order applied to the first part of the tags (before the underscores), for example:</p>
  
  <pre><code>size
  color
  weight
  category
  </code></pre>
  
  <p>So with the above example, I'd want to end up with the list sorted like:</p>
  
  <pre><code>size_large
  color_black
  color_brown
  weight_10
  category_electronics
  </code></pre>
  
  <p>If the full tag names were all known, this would be simple, as I could just do something like:</p>
  
  <pre><code>{% assign tags = 'size_large,color_black,color_brown,weight_10,category_electronics' | split: ',' %}
  
  {% for t in tags %}  
      {% assign tag = t | strip %}
      {% if product.tags contains tag %}
            &lt;li&gt;{{ tag }}&lt;/li&gt;
        {% endif %}
      {% endfor %}
  {% endif %}
  </code></pre>
  
  <p>However, that is not the case.  The value after the underscore in the tag is variable, and there could be multiple occurrences of any of the tag groups (ie. size above) for any single product.</p>
  
  <p>It seems I'd need to use some kind of associative array to make this happen, but I can't quite wrap my head around how that would be done.</p>