title: Mustache Conditions and Loops
body: <p>Here are the resources:</p>
  
  <p><strong>JSON</strong></p>
  
  <pre><code>{
    "badges":{
      "unlocked": [
        {"name": "Win 1"},
        {"name": "Win 2"},
        {"name": "Win 3"}
      ],
      "locked":[
        {"name": "Lose 1"},
        {"name": "Lose 2"},
        {"name": "Lose 3"}
      ]
    }
  }
  </code></pre>
  
  <p><strong>Algorithm</strong></p>
  
  <pre><code>{{ if_has_badges }}
  &lt;div class="badges"&gt;
    &lt;h1&gt;Badges&lt;/h1&gt;
  
    {{ if_has_badges_unlocked }}
      &lt;div class="badges-unlocked"&gt;
        &lt;h2&gt;Unlocked!&lt;/h2&gt;
        {{ loop_badges_unlocked }}
        &lt;a href="#" class="badge"&gt;
          &lt;strong&gt;{{ name }}&lt;/strong&gt;
        &lt;/a&gt;
        {{ end_loop_badges_unlocked }}
      &lt;/div&gt;
    {{ end_if_has_badges_unlocked }}
  
    {{ if_has_badges_locked }}
      &lt;div class="badges-locked"&gt;
        &lt;h2&gt;Locked!&lt;/h2&gt;
        {{ loop_badges_locked }}
        &lt;a href="#" class="badge"&gt;
          &lt;strong&gt;{{ name }}&lt;/strong&gt;
        &lt;/a&gt;
        {{ end_loop_badges_locked }}
      &lt;/div&gt;
    {{ end_if_has_badges_locked }}
  
  &lt;/div&gt;
  {{ end_if_has_badges }}
  </code></pre>
  
  <p>How I can write this algorithm to work with Mustache compiler?</p>
  
  <p>I need to do this to work with two sides, first is the RubyOnRails application and the second is the client-side (JavaScript).</p>