Slim
A cheatsheet by @rstacruz|Refreshed about 3 years ago.Refresh|View source on Github

Example

Example

doctype html
html
  head
    title Slim Examples
    meta[charset='utf-8']
    meta(name="keywords" content="template language")
    meta name="author" content=author
    meta property='og:image' content=asset_url('foo.png')
    meta property='og:image' content=(path_to_user user)
    meta(
      property='description'
      content='this is the song that never ends')

Attributes

Attributes

meta[charset='utf-8']
meta(name="keywords" content="template language")
meta name="author" content=author

You can use parentheses, brackets, or none at all.

Ruby attributes

Ruby attributes

a class=[:menu,:highlight]

You can use Ruby expressions in attributes.

Hash attributes

Hash attributes

.card *{'data-url' => place_path(place)}

You can destructure Ruby hashes as attributes.

Inline Ruby

Inline Ruby

ruby:
  def foobar
    "hello"
  end

div= foobar

Inline Markdown

Inline Markdown

markdown:
  ### On Markdown

  I am *Markdown* _text_!
  {: .classname}

Slim can handle your Markdown content for longer content blocks or code.
Depending on your parser, like Kramdown, other features might work, like assigning attributes or classes.

Embedded JavaScript

Embedded JavaScript

javascript:
  alert('Slim supports embedded javascript!')

Comments

Comments

/ Comment
/! HTML comment

Ruby

Ruby

== yield
= t('.hello')
- 3.times do |i|
  div

Verbatim text

Verbatim text

div
  | This is text
    it is nice

Advanced whitespaces

Advanced whitespaces

div
  ' This appends a whitespace
div
  |  This hackily prepends a whitespace
div
  => 'This appends a whitespace'
div
  =< 'This prepends a whitespace'

Inline HTML

Inline HTML

<div class='foo'>
  - if articles.empty?
    | Nothing here
</div>

Inline tags

Inline tags

ul
  li: a(href='/') Home
This cheat sheet can be found in the following categories: