开发者

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开发者_如何学Python})
).replace('#sammy_main')


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.


For me, this worked:

this.use('Template', "[object HTMLScriptElement]"); // If not view data are not rendered
[...]
var template = $('#tmpInmuebleDetalle')[0];
this.partial(template);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜