<!-- ko with: function() { $context.extraCssClass = {'my-css-class': true}; return $data } --> {{ my/sub/template.mustache }} <!-- /ko -->
What is happening here is that we use the with binding to call a function that installs extraCssClass on $context. Then we return $data to continue using the same $data scope with inner data-bind calls.
Then in template.mustache, you can consume the css class by checking $context:
<div data-bind="css: $context.extraCssClass || {}"></div>
I don't think this is *too* hacky, and it allows you inject custom variables without adding special logic to your viewmodel.
Let me know what you think!
No comments:
Post a Comment