I'm not sure yet, but I think I have found a solution. After looking at the KO documentation for the nth time, I found this: By supplying additional values for child bindings .
For those of you who are: dr: I can use this binding handler to display any variable in the template in each subcontext, which is exactly what I was looking for. In other words, it becomes possible:
ViewModel
<script> ViewModel = { Helpers: { foo: function(message) {return message;} }, someList: [ 'foo', 'bar', 'baz' ] } </script>
HTML
<div data-bind="text:helpers.foo('Helpers.foo can be used because we are in the root context')"></div> <div data-bind="foreach: someList"> <div data-bind="text:helpers.foo('We are in the context of someList. This will fail.')"></div> </div> <div data-bind="withProperties:{Helpers:Helpers}"> <div data-bind="foreach: someList"> <div data-bind="text:helpers.foo('Helpers.foo can now be used inside every subcontext, thanks to the withProperties custom binding')"> </div> </div> </div>
In my case, custom wrapper bindings can be applied automatically when loading for each template, so this seems like a great solution for me!
I will try this method and publish the following information if it happens that I missed something. This question will be left open for a short time, because I can not accept my own answer so quickly. Meanwhile, do not hesitate to publish your decisions, I am sure that there are several more approaches to solving this issue.
source share