Generic template interface for Crystal
Branch: master
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
spec Add support (#15) Feb 10, 2018
src Add support (#15) Feb 10, 2018
.gitignore ignore lib Apr 5, 2017
.travis.yml Added latest version to crystal in travis.yml (#17) Sep 26, 2018
LICENSE Initial commit Feb 14, 2016 Mention support in (#16) Feb 11, 2018
shard.yml Add support (#15) Feb 10, 2018

Kilt Build Status Dependency Status devDependency Status

Generic templating interface for Crystal.


Simplify developers' lives by abstracting template rendering for multiple template languages.

Supported out of the box

Language File extensions Required libraries Maintainer
ECR .ecr none (part of the stdlib)
Mustache .mustache crustache @MakeNowJust
Slang .slang slang @jeromegn
Temel .temel temel @f
Crikey .crikey crikey @domgetter
Liquid .liquid liquid @jetcommerce

See also: Registering your own template engine.


Add this to your application's shard.yml:

    github: jeromegn/kilt

  # Any other template languages Crystal shard


  • Kilt essentially adds two macros Kilt.embed and Kilt.file, the code is really simple.
  • Add template language dependencies, as listed in the support table above.

Both macros take a filename and a io_name (the latter defaults to "__kilt_io__")


require "kilt"

# For slang, add:
require "kilt/slang"

# With a Class

class YourView
  Kilt.file("path/to/template.ecr") # Adds a to_s method
puts # => <compiled template>

# Embedded

str = Kilt.render "path/to/template.slang"

# or

str = do |__kilt_io__|
  Kilt.embed "path/to/template.slang"

puts str # => <compiled template>

Registering your own template engine

Use Kilt.register_engine(extension, embed_command) macro:

require "kilt"

module MyEngine
  macro embed(filename, io_name)
    # ....

Kilt.register_engine("myeng", MyEngine.embed)

This can be part of your own my-engine library: in this case it should depend on kilt directly, or this could be a part of adapter library, like: kilt-my-engine, which will depend on both kilt and my-engine.


Please contribute your own "adapter" if you create a template language for Crystal that's not yet supported here!

  1. Fork it ( )
  2. Create your feature branch (git checkout -b my-awesome-template-language)
  3. Commit your changes (git commit -am 'Add my-awesome-template-language')
  4. Push to the branch (git push origin my-awesome-template-language)
  5. Create a new Pull Request