Skip to content

Instantly share code, notes, and snippets.

@wojtekmach
Created January 3, 2012 23:36
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wojtekmach/1557585 to your computer and use it in GitHub Desktop.
Save wojtekmach/1557585 to your computer and use it in GitHub Desktop.
Slim + handlebars
module Tilt
class HandlebarsSlimTemplate < ::Slim::Template; end
register HandlebarsSlimTemplate, :handlebars_slim
end
class Slim::EmbeddedEngine
register :handlebars, TagEngine, tag: :script, attributes: { type: "text/x-handlebars" }
register :handlebars_slim, TagEngine, tag: :script, attributes: { type: "text/x-handlebars" }, engine: StaticTiltEngine
end
@SergXIIIth
Copy link

Thanks for Gist. Could you also share how to integrate it into Rails and show Rails view example. Thank you very much

@halloffame
Copy link

@SergXIIIth You just need to include it in an initializer file (/config/initializers/slim.rb for example), then you will be able to use the handlebars: tag in your slim files.

I'm assuming something changed with slim, but now Slim::EmbeddedEngine doesn't work anymore. I had to do just Slim::Embedded instead.

class Slim::Embedded
  register :handlebars, TagEngine, tag: :script, attributes: { type: "text/x-handlebars" }
  register :handlebars_slim, TagEngine, tag: :script, attributes: { type: "text/x-handlebars" }, engine: StaticTiltEngine
end

https://github.com/slim-template/slim/blob/master/lib/slim/embedded.rb#L63

@deepakkumarnd
Copy link

@wojtekmach Could you provide a sample, template example? How can I give an id to embedded code

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