The Nayjest solution should work if you change the visible binding to an if binding - this way it will not try to display parts with a header dependency.
The best solution, however, probably consists of two patterns and their execution based on type. You may have a method on a virtual machine that takes $ data and returns, for example, "auditTemplate" or "commentTemplate" depending on the result of something like $ data instanceof Audit. Then you will have two templates built into the script tags with these identifiers:
<script id="auditTemplate" type="text/html"> <div class="audit"> </div> </script> <script id="commentTemplate" type="text/html"> <div class="comment"> </div> </script>
And then in your virtual machine you will have something like:
this.getTemplate = function(data) { return (data instanceof Audit) ? 'auditTemplate' : 'commentTemplate' }
On the html page you will do something like:
<div databind="template: {name:$parent.getTemplate($data), data: $data}"></div>
source share