title: How to template If-Else structures in data-bound views?
body: <p>I constantly find myself using this idiom in KO-based HTML templates:</p>
  
  
  
  <pre class="lang-html prettyprint-override"><code>&lt;!-- ko if: isEdit --&gt;
  &lt;td&gt;&lt;input type="text" name="email" data-bind="value: email" /&gt;&lt;/td&gt;
  &lt;!-- /ko --&gt;
  &lt;!-- ko ifnot: isEdit --&gt;
  &lt;td data-bind="text: email"&gt;&lt;/td&gt;
  &lt;!-- /ko --&gt;
  </code></pre>
  
  <p>Is there a better/cleaner way to do conditionals in KO, or is there a better <em>approach</em> than just using traditional if-else constructs?</p>
  
  <p>Also, I would just like to point out that some versions of Internet Explorer (IE 8/9) don't parse the above example correctly. Please see <a href="https://stackoverflow.com/questions/12613668/knockout-virtual-elements-between-tr-tags-in-ie-browsers">this SO question</a> for more information. The quick summary is, don't use comments (virtual bindings) inside table tags to support IE. Use the <code>tbody</code> instead:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;tbody data-bind="if: display"&gt;&lt;tr&gt;&lt;td&gt;hello&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;
  </code></pre>