Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?


Failed to load latest commit information.
Latest commit message
Commit time

Slime Continuous Integration Hex Version License

A refreshing way to slim down your markup in Elixir.

Slime is an Elixir library for rendering Slim-like templates as HTML.

For use with Phoenix, please see PhoenixSlime.

Easily turn this:

doctype html
    meta name="keywords" description="Slime"
    title = site_title
      alert('Slime supports embedded javascript!');
        = [1, 2], fn x ->
          li = x

Into this:

<!DOCTYPE html>
  <meta name="keywords" description="Slime">
  <title>Website Title</title>
  <script>alert('Slime supports embedded javascript!');</script>

  <div class="class" id="id">

With this:

Slime.render(source, site_title: "Website Title")



Attributes can be assigned in a similar fashion to regular HTML.

a href="" target="_blank" Elixir
<a href="" target="_blank">Elixir</a>

Elixir expressions can be used as attribute values using the interpolation syntax.

a href="#{my_variable}" Elixir
<a href="">Elixir</a>

Boolean attributes can be set using boolean values

input type="checkbox" checked=true
input type="checkbox" checked=false
<input type="checkbox" checked>
<input type="checkbox">

There is a literal syntax for class and id attributes
<div class="foo bar"></div>
<select class="bar"></select>
<div id"foo"></div>
<body id="bar"></body>


Elixir can be written inline using - and =.

- evalutes the expression. = evalutes the expression, and then inserts the value into template.

- number = 40
p = number + 2

The interpolation syntax can be used to insert expressions into text.

- name = "Felix"
p My cat's name is #{name}
<p>My cat's name is Felix</p>


Lines can be commented out using the / character.

/ p This line is commented out
p This line is not
<p>This line is not</p>

HTML <!-- --> comments can be inserted using /!

/! Hello, world!
<!-- Hello, world! -->


We can use the regular Elixir flow control such as the if expression.

- condition = true
= if condition do
  p It was true.
- else
  p It was false.
<p>It was true.</p>


There are shortcuts for common doctypes.

doctype html
doctype xml
doctype transitional
doctype strict
doctype frameset
doctype 1.1
doctype basic
doctype mobile
<!DOCTYPE html>
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "">
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "">


Elixir's collection manipulation expressions can be used to iterate over collections in your templates.

- names = ["Sarah", "Mia", "Harry"]

= names, fn name ->
  p = name

/! for comprehension
= for name <- names do
  h1 = name
<!-- -->

<!-- for comprehension -->

Embedded engines


  console.log("Test javascript");

  body {
    color: black;

  a = [1, 2, 3]
  b =, &(&1 + 1))

  Hello from <%= "eex" %>

You can define your own embedded engine in slime application config:

# config.exs
config :slime, :embedded_engines, %{
  markdown: MyApp.MarkdownEngine

# markdown_engine.ex
defmodule MyApp.MarkdownEngine do
  @behaviour Slime.Parser.EmbeddedEngine

  def render(text, _options) do

Because the engines are being read on compile time you need to recompile the library after you have added new engines. You can do this by:

mix deps.compile slime --force


Templates can be compiled into module functions like EEx templates, using functions Slime.function_from_file/5 and Slime.function_from_string/5.

To use slime templates (and Slime) with Phoenix, please see PhoenixSlim.

Differences to Ruby Slim

We aim for feature parity with the original Slim implementation, but we deviate in some respects. We do this to be true to Elixir – just like the original Slim implementation is true to its Ruby foundations.

For example, in Slime you do

= if condition do
  p It was true.
- else
  p It was false.

where Ruby Slim would do

- if condition
  p It was true.
- else
  p It was false.

Note the do and the initial =, because we render the return value of the conditional as a whole.


If you have trouble locating exceptions in Slime templates, you can add

config :slime, :keep_lines, true

to your config.exs file. With this option Slime will keep original template lines in result eex and html. Keep in mind, that output is slightly different from default Slime output, for example | works like ', and empty lines are not ignored.


Feedback, feature requests, and fixes are welcomed and encouraged. Please make appropriate use of Issues and Pull Requests. All code should have accompanying tests.


MIT license. Please see LICENSE for details.