knockout/knockout — pull request #1003 by mbest (2013-12-21 01:02:26+00:00)
Title: Templates: template-name evaluation could set observable

I have following setup:
- knockout 2.2.1
- external knockout template engine 2.0.5

Interestingly until now it worked like a charm. But a single usecase now breaks it - I'm having an external template which uses another external template (altough from my perspective I use this setup at various other places on the same page).

If the **name option is an observable**, it **gets *set*** with the current $data object instead of reading its value.

If I write ```... template: {name: childTemplateName() } ...``` instead of ```template: {name: childTemplateName } ...``` (note parentheses) it works ***with* the following workaround** applied to knockout:

This line
```javascript
var templateName = typeof(template) == 'function' ? template(bindingContext['$data'], bindingContext) : template;
```
being changed to
```javascript
var templateName = typeof(template) == 'function' && ko.isObservable(template) == false ? template(bindingContext['$data'], bindingContext) : ko.utils.unwrapObservable(template);
```
(or
```javascript
var templateName = typeof (ko.utils.unwrapObservable(template)) == 'function' == true ? template(bindingContext['$data'], bindingContext) : ko.utils.unwrapObservable(template);
```
)

fixed the issue for me (note the **observable check** and the **unwrap call**).

Although I think it has something to do with the external template engine, ```template``` being an observable should be protected from being set.