title: Shopify liquid - get products by string
body: <p>I have the slug of a collection. And I know that I can get the products of a collection by slug by doing:</p>
  
  <pre><code>collections.this-is-my-slug.products
  </code></pre>
  
  <p>However I have this slug as string assigned to a variable called collection_slug. </p>
  
  <p>If I write:</p>
  
  <pre><code>collections.collection_slug.products
  </code></pre>
  
  <p>It does not work. As the string does not get put into there...</p>
  
  <p>How can I solve this?</p>
  
  <p>Here is the code:</p>
  
  <pre><code>{% assign collection_url = block.settings.collection_url | split: '/' %}
  {% assign collection_slug = collection_url.last %}
  
  {% for product in collections.collection_slug.products %}
      product
  {% endfor %}
  </code></pre>
  
  <p><strong>SOLVED IT BY:</strong></p>
  
  <pre><code>{% for collection in collections %}
   {% if collection.url == block.settings.collection_url %}
      {% for product in collection.products %}
       ...
  </code></pre>