SteveSanderson/knockout — Issue #365: Native Template Engine: foreach; templateOptions
Author: troyji
Created: 2012-03-07 15:16:49+00:00
State: open

This is a spin off of issue #246

In short, there is not way to pass additional arguments into a named template when using the 'foreach' binding.

Below is a use case for 'templateOptions'. In particular, the workaround suggested in the issue above does not work for passing options while using 'foreach' instead of 'data'. Imagine a tree of nodes where each node consists of an item and children. We will use a recursive template to generate the tree. The root binding would look like this:

```
data-bind="template: { name: 'nodeTemplate', data: rootNode }"
```

The template would render a node's children using this binding:

```
data-bind="template: { name: 'nodeTemplate', foreach: children }"
```

Now if we want to pass options for the root, we can do:

```
data-bind="template: { name: 'nodeTemplate', data: { node: rootNode, options: '...'}"
```

However, there is no way to pass additional options when using 'foreach'.

We could do this before like this:

```
data-bind="template: { name: 'nodeTemplate', foreach: children, templateOptions: '...' }"
```