title: How to auto check checkboxes using Twig template?
body: <p>I want to auto-check check boxes in the HTML. I've managed to get this to work, but it's kinda messy in the template:</p>
  
  <pre><code>&lt;ul&gt;
      {% for tag in tags %}
          {% set selected = false %}
          {% for article_tag in article.tags %}
              {% if article_tag.id == tag.id %}
                  {% set selected = true %}
              {% endif %}
          {% endfor %}
          &lt;li&gt;&lt;input type="checkbox" name="tags[]" value="{{ tag.id }}" {% if selected %}checked{% endif %}&gt; {{ tag.name }}&lt;/li&gt;
      {% endfor %}
  &lt;/ul&gt;
  </code></pre>
  
  <p>So the data I'm loading in is like this (in JSON format):</p>
  
  <pre><code>[
      'tags' =&gt; [
          {'id'=&gt; 1, 'name'=&gt;'Travel'},
          {'id'=&gt; 2, 'name'=&gt;'Cooking'},
      ],
      'article' =&gt; {
          'tags' =&gt; [
              {'id'=&gt; 1, 'name'=&gt;'Travel'},
          ],
      }
  ]
  </code></pre>
  
  <p>Also, I'm not using Symfony (I'm using Slim's Twig library) so not sure if Symfony has some stuff in it's framework for doing stuff with Twig. If so, it won't work for me :(</p>