Skip to content

Instantly share code, notes, and snippets.

@fgrehm
Last active November 30, 2020 16:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fgrehm/4489503 to your computer and use it in GitHub Desktop.
Save fgrehm/4489503 to your computer and use it in GitHub Desktop.
knockout.js + handlebars
class HandlebarsTemplateEngine extends ko.templateEngine
renderTemplateSource: (compiledTemplate, bindingContext, options) ->
data = bindingContext.$data
htmlResult = compiledTemplate(data)
ko.utils.parseHtmlFragment(htmlResult)
makeTemplateSource: (template, templateDocument) ->
throw "Could not find a template named: '#{template}'" unless JST[template]
JST[template]
# TODO: Figure out what this method is supposed to do
isTemplateRewritten: ->
true
ko.setTemplateEngine new HandlebarsTemplateEngine
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment