Does "templateOptions" work with the "foreach" binding?
I tested the following, and the ${$item.header} span is empty.
<script type = "text/x-jquery-tmpl" id = "tableTemplate">
<li class="liClosed"><img src="images/table.gif"> </img><span data-bind='text:tableName'></span><span class='tableSpan'></span>
<ul data-bind="template: {name:'serverdataAttributeTemplate', foreach: attributes, afterRender: convertTrees}">
</ul>
<ul data-bind="template: {name:'userProfileTemplate', foreach: profiles, afterRender: convertTrees, templateOptions: { header: 'table1' } }">
</ul>
</li>
</script>
<script type = "text/x-jquery-tmpl" id = "serverdataAttributeTemplate">
<li><img src="images/attribute.gif"> </img><span data-bind='text:attributeName'></span>
</li>
</script>
<script type = "text/x-jquery-tmpl" id = "userProfileTemplate">
<li class="liClosed"><img src="images/profile.gif"> </img><span data-bind='text:profileName'></span><span class='profileSpan'></span>
<input type='checkbox' data-bind='checked:isUsed'></input>
<span>${$item.header}</span>
<ul data-bind="template: {name:'serverdataPreferenceTemplate', foreach: preferences, afterRender: convertTrees }">
</ul>
</script>