sammy.js

Rendering a local template with Sammy.js


I am using sammy for a web application that needs to render templates stored inline in the page. I am using a script tag to contain the markup, which is haml.

Is there a good, idiomatic way to render templates that are not loaded via ajax request? I have a solution, but I am not happy with it. $('#start_haml') is the script element containing the markup and $('#sammy_main') is the container to render into.

app.get '#/', (context) ->

context.load($('#start_haml')).then((data) ->
  context.interpolate(data, {helpers: view_helpers})
).replace('#sammy_main')

Solution

  • Thanks to Aaron Quint for answering me on the Sammy.js mailing list

    The answer is simple, but worth leaving here since it is not mentioned in the documentation.

    context.render($('#start_haml'), {helpers: view_helpers})
      .replace '#sammy_main'
    

    NB. The second parameter to render() is the view data.