KO cannot find template with ID

durandal, javascript, knockout.js

Solution

The short answer: You can't currently use Knockout templates inside of Durandal. However, as nemesv pointed out, if you put your named template outside of Durandal, ko is able to find them. For example, anywhere outside of the `<div id="applicationHost"></div>` element.

The other workarounds are to either use Durandal's compose functionality, or just inline the templates as anonymous.

Knockout templates will probably be supported in the near future.

I finally dug these answers up on the Durandal google group,

- Mixing knockout templates with durandal compose

- knockout can't find templates inside of views

Problem

I've used Knockout templates before, so I'm not sure why this isn't working for me. I tried two different styles of ko markup, neither work. ``` <!-- more nesting levels --> <div class="cal-day-tps" data-bind="foreach: timePeriods"> <div class="cal-day-tp-cont"> <div data-bind="template: { name: 'tp-ed-templ', data: $data }"></div> //both of these methods fail <!-- ko template: { name: 'tp-ed-templ', data: $data } --> <!-- /ko --> </div> </div> <!-- /more nesting levels --> <script type="text/html" id="tp-ed-templ"> <!-- bunch of markup --> </script> ``` I just get the error "Cannot find template with ID tp-ed-templ". Probably just a typo, but I haven't been able to find it. - I'm using KO in the context of Durandal, though this shouldn't make a difference. - Tried declaring the template before usage, didn't help. - Someone else ran into the same thing with no solution either It seems to be an issue with Durandal, not Knockout. I tried some extremely simple cases in vanilla durandal setups, and it still does the same thing. Even tried putting the script in the same nested location as the binding, no dice.

Original source

Related problems