クイックリファレンス

Slim テンプレートエンジン チートシート

Ruby 用テンプレートエンジン Slim のクイックリファレンス:簡潔なマークアップ構文、属性記法、Ruby 式展開、ループ、組み込みエンジンを整理。

· 公開日

基本例

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.

タグとネスト

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

属性

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

Ruby コードの評価

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

ループ

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

組み込みエンジン

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

sass:
  body
    color: #333

リファレンス

関連テーマ