2011-07-10 46 views
3

我正在使用sammy来创建需要呈现存储在页面中的模板的Web应用程序。我正在使用脚本标记来包含标记,这是haml。使用Sammy.js呈现本地模板

有没有一种很好的,惯用的方法来呈现不通过ajax请求加载的模板?我有一个解决方案,但我不满意它。 $('#start_haml')是包含标记的脚本元素,$('#sammy_main')是要渲染的容器。

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

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

回答

3

感谢阿龙昆特为answering me on the Sammy.js mailing list

答案很简单,但值得留在这里,因为它没有在文件中提及。

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

NB。 render()的第二个参数是视图数据。