Skip to content

Instantly share code, notes, and snippets.

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 tbeseda/2772033 to your computer and use it in GitHub Desktop.
Save tbeseda/2772033 to your computer and use it in GitHub Desktop.
How I do one-off front-end templating with Handlebars, HAML, and CoffeeScript.
%script#instagram-thumbnail-popover{type: "text/x-handlebars-template"}
%img{src: "{{images.low_resolution.url}}"}/
%i.icon-heart/
{{likes.count}} likes
%script#instagram-thumbnails{type: "text/x-handlebars-template"}
%ul.thumbnails
{{#data}}
%li.span1
%a.thumbnail{href: "{{link}}", title: "{{caption.text}}", data: {content:"{{> popover}}"}}
%img{src: "{{images.thumbnail.url}}"}
{{/data}}
$ ->
Handlebars.registerPartial 'popover', $('#instagram-thumbnail-popover').html()
instagram_template = Handlebars.compile $('#instagram-thumbnails').html()
$.getJSON "/instagram/#{instagram_handle}", (response) ->
instagram_html = instagram_template response
$instagram.append instagram_html
$instagram.find('.thumbnail').popover placement: 'bottom'
@tbeseda
Copy link
Author

tbeseda commented May 22, 2012

Not advisable to compile templates at runtime at any sort of significant scale, but works great for single page apps when you can compile templates one at time, as needed, on the fly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment