Newsletter
Join the Community
Subscribe to our newsletter for the latest news and updates
Minimalistic HTML templates for Elixir, inspired by Slim.
Slime is an Elixir template engine that renders Slim-like indentation-based markup into HTML, letting Phoenix developers write templates with far less closing-tag boilerplate.
Slime is an open-source, MIT-licensed Elixir library that converts Slim-style template source into HTML strings. It takes a template as input (a string containing indentation-sensitive markup and embedded Elixir expressions) and produces HTML output via the Slime.render/2 function, which accepts a keyword list of variables bound in the template. Slime is developed by the slime-lang GitHub community and is designed to slot into Phoenix applications through the companion PhoenixSlime project.
Slime stands out by translating Ruby Slim's concise markup to Elixir's expression model, while adding features like embedded engines, doctype shortcuts, and precompilation that EEx doesn't provide out of the box. Here are the concrete capabilities:
.class and #id shortcuts, attributes on a single line, and indentation hierarchy.- (side effect) and = (insert into output); interpolate variables inside text as #{var} and inside attribute values.javascript:, css:, elixir:, and eex:; define custom engines in config :slime, :embedded_engines.doctype html, doctype xml, doctype transitional, doctype strict, doctype frameset, doctype 1.1, doctype basic, and doctype mobile.Slime.function_from_file/5 and Slime.function_from_string/5 to compile templates into module functions, matching EEx workflow.checked=true to render the attribute or checked=false to omit it entirely.config :slime, :keep_lines, true to keep original template line numbers in output EEx and HTML for easier exception tracing.Slime is a fit for Elixir and Phoenix developers who want a more concise, indentation-based HTML templating style. Specifically:
With Slime you can render Slim-style templates both at runtime and at compile time, and extend it with custom embedded engines. Concrete uses include:
.slime files in Phoenix via PhoenixSlime, with access to the view's assigns.Slime.render/2 directly on template strings, passing assign values such as site_title: "Website Title" to bind variables.markdown: blocks.Templates are written in Slim-inspired indentation syntax. At runtime you call Slime.render(source, assigns) to render a string; at compile time you can use Slime.function_from_string/5 or Slime.function_from_file/5 to generate module functions that return the HTML. Slime's embedded engines are read at compile time, so new engines require recompiling the dependency with mix deps.compile slime --force.
Slime aims for feature parity with the original Slim but follows Elixir idioms. Where Ruby Slim writes - if condition, Slime requires Elixir's do/end form plus an initial = because the conditional's return value is inserted into the template: = if condition do ... - else .... This makes conditionals and loops behave as pure Elixir expressions.
Yes. Slime is released under the MIT license, so it is free to use, modify, and distribute in commercial and personal projects.
Yes, through the companion project PhoenixSlime, which connects Slime templates to Phoenix's view rendering pipeline, letting you use .slime files as your Phoenix view templates.
Configure config :slime, :embedded_engines with a map of engine names to modules, then implement the Slime.Parser.EmbeddedEngine behaviour with a render/2 callback. Because engines are read at compile time, run mix deps.compile slime --force after changing the config.
Set config :slime, :keep_lines, true in your config.exs to preserve original template line numbers in the generated EEx/HTML output. Be aware the output differs slightly: | behaves like ', and empty lines are not ignored.
