You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
i'd love to use sammy with jammit which supports packaging the templates instead of loading them via http. since sammy does not (yet?) support local templates, i hacked together a small workaround which extends the render method, loads the template and returns an object, tricking sammy to use it as a jquery element.
loading the templates upfront might be especially interesting for small applications with a few templates. i don't think it would require much code to do this and could try to implement a non-hacky version (without introducing a dependency on JST) if you think this is a good idea.
cheers,
daniel
The text was updated successfully, but these errors were encountered:
I hadnt seen how jammit packages templates until just now and it presents an interesting problem. Sammy does support packaging templates, just in a different (albiet more standard way) of being able to load them from DOM elements or <script> tags on the page. jQuery-tmpl and Mustache particularly work well this way. render() and partial() can take a string (the name of a template) or a jQuery or DOM element. The use case is simple, embed the template in a script tag on the page:
<script id="name-template" type="text/mustache" data-engine="mustache">
I'm a template named {{name}}.
</script>
I like this approach as it lets all the view logic be embeded with the rest of the view. With JST it looks like JST 'templates' are just functions, similar to the way we define template 'engines' in Sammy. In this way you might be able to use interpolate() directly (not tested):
var rctx = new RenderContext(this);
var engine = function(content, data) { return JST.nametemplate(data); }
rctx.interpolate({name: 'NAME'}, engine).appendTo('#main');
hey aaron,
i'd love to use sammy with jammit which supports packaging the templates instead of loading them via http. since sammy does not (yet?) support local templates, i hacked together a small workaround which extends the
render
method, loads the template and returns an object, tricking sammy to use it as a jquery element.app: https://github.com/rubiii/sam/blob/master/public/javascripts/application.js
workaround: https://github.com/rubiii/sam/blob/master/public/javascripts/sammy-jst.js
loading the templates upfront might be especially interesting for small applications with a few templates. i don't think it would require much code to do this and could try to implement a non-hacky version (without introducing a dependency on JST) if you think this is a good idea.
cheers,
daniel
The text was updated successfully, but these errors were encountered: