This page is not available in every language. Missing translations are disabled in the language selector.

Quick reference

Slim Cheatsheet

Quick reference guide for Slim template engine in Ruby, covering concise syntax, HTML tag helpers, conditionals, loops, and partials.

· Published

Basic Example

doctype html
html
  head
    title Slim Examples
    meta name="keywords" content="template language"

  body
    h1 Markup examples
    #content
      p This example shows how to use Slim.

Tags and Nesting

p
  | First line
  | Second line
h1.title#header Header text
a href="https://example.com" title="Home" Home Page

Attributes

a href=url title=@title Link
input type="checkbox" checked=true
div class=["one", "two"]
div id="entry-#{entry.id}"

Ruby Code Evaluation

- if user.admin?
  p Welcome Administrator!
- else
  p Welcome Guest!
= current_user.name
== raw_html_content

Loops

ul
  - @items.each do |item|
    li = item.name

Embedded Engines

javascript:
  alert('Hello from Slim!');

sass:
  body
    color: #333

References

Related topics