Menu

gitpiper

Slim Cheat Sheet in December 2024

Last Updated: 3 December 2024

README.md

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

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

a class=[:menu,:highlight]

You can use Ruby expressions in attributes.

Hash attributes

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

You can destructure Ruby hashes as attributes.

Inline Ruby

ruby:
  def foobar
    "hello"
  end

div= foobar

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

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

Comments

/ Comment
/! HTML comment

Ruby

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

Verbatim text

div
  | This is text
    it is nice

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

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

Inline tags

ul
  li: a(href='/') Home

References


338+ more cheat sheets for you in December 2024

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2024 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️