title: Shopify Theme Development - For loop that checks if article.tags contains a sections variable
body: <p>I am trying to pull through related blog posts if the article.tags == the string given within the section settings.</p>
  <p>I have tried a few different variations but to no effect. My code looks like this (don't worry about the content within the if loop, this is all fixed into shape by the CSS):</p>
  <pre><code>{% for article in blogs.news.articles limit:1 %}
      {% if article.tags == section.settings.brand-news-tag | strip_html %}
          {% assign image_src = article.image.src | img_url: 'large' %}
          &lt;div class=&quot;brand-page-featured-news-blogs&quot;&gt;
              &lt;div class=&quot;brand-page-featured-news-article&quot;&gt;
                  &lt;a href=&quot;{{ article.url }}&quot; class=&quot;box-link&quot;&gt;&lt;/a&gt;
                  &lt;div class=&quot;brand-page-featured-news-article-image&quot; style=&quot;background-image: url({{ image_src }})&quot;&gt;
                      &lt;div class=&quot;brand-page-featured-news-article-image-contain&quot;&gt;
                          &lt;div class=&quot;brand-page-featured-news-article-image-overlay&quot;&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class=&quot;brand-page-featured-news-article-contain&quot;&gt;
                      &lt;h6 class=&quot;brand-page-featured-news-article-title&quot;&gt;{{ article.title }}&lt;/h6&gt;
                      &lt;div class=&quot;brand-page-featured-news-article-content&quot;&gt;
                          &lt;p class=&quot;brand-page-featured-news-article-published&quot;&gt;{{ article.published_at | date: &quot;%d %B 20%y&quot; }}&lt;/p&gt;
                          &lt;p class=&quot;brand-page-featured-news-article-text&quot;&gt;{{ article.content }}&lt;/p&gt;
                          &lt;div class=&quot;brand-page-featured-news-article-button&quot;&gt;
                              &lt;div class=&quot;brand-page-featured-news-article-button-text&quot;&gt;
                                  Read More
                              &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      {% endif %}
  {% endfor %}
  {% schema %}
      {
          &quot;name&quot;: &quot;Featured News&quot;,
          &quot;settings&quot;: [
              {
                  &quot;id&quot;: &quot;brand-news-tag&quot;,
                  &quot;type&quot;: &quot;text&quot;,
                  &quot;label&quot;: &quot;Brand News Tag&quot;,
                  &quot;default&quot;: &quot;brandnametag&quot;
              }
          ]
      }
  {% endschema %}
  {% stylesheet %}
  {% endstylesheet %}
  {% javascript %}
  {% endjavascript %}
  </code></pre>
  <p>This is the line in question:</p>
  <pre><code>{% if article.tags == section.settings.brand-news-tag | strip_html %}
  </code></pre>
  <p>I have tried to use a few other variations like without the '| strip_html'. I have tried to put it inside quotes like this {% if article.tags == &quot;'&quot; and section.settings.brand-news-tag and &quot;'&quot; %}. I have also tried to use 'contains' opposed to an '=='.</p>
  <p>How can I use a variable within the if statement?</p>
  <hr />
  <p>I have tried using -</p>
  <pre><code>{% if article.tags contains section.settings.brand-news-tag %}
  </code></pre>
  <p>I have also tried without any if statement narrowing down the blogs.news. this works as expected. Meaning it is something to do with this if statement not comparing to the blog tags. Although I have directly copied the blog tag in from the blog post to go into the variable within the section.</p>
  <p>This also doesn't work -</p>
  <pre><code>{% for article in blogs.news.articles limit:1 %}
      {% if section.settings.brand-news-tag != '' %}
          {% assign blogfilter = section.settings.brand-news-tag | strip %}
      {% endif %}
      {% if article.tags contains blogfilter %}
  </code></pre>
  <p>This also doesn't work (Goodfellow is the tag copied) -</p>
  <pre><code>{% for article in blogs.news.articles limit:1 %}
      {% if article.tags contains 'Goodfellow' %}
  </code></pre>
  <p>Here are some images of the blog side of things:</p>
  <p><a href="https://i.stack.imgur.com/FeXg5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FeXg5.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/atERT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/atERT.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/GkFa9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GkFa9.png" alt="enter image description here" /></a></p>