Slimとは
Railsで使えるテンプレートエンジン
Slimの他にHamlなどがあるが、Slimの方が記述方法がシンプル。
HTMLをタグではなく階層構造(インデント)で表す。閉じタグは省略可能。
テンプレートエンジンとは
MVCフレームワークにおいて、Controllerで定義した変数をviewで使用できるようにする仕組み。
Railsでは標準でERBが採用されている。
文法
「/」 コメントアウト
test.slim
/これはコメントです
tr
th
th
出力
test.html
<tr>
<th></th>
<th></th>
</tr>
「-」 Rubyのコードを記述
test.slim
tbody
- @tasks.each do |task|
tr
td
td
「=」 Rubyのコードを出力する
test.slim
tr
td= link_to task.name, task
td= task.created_at
「# / .」 id属性・クラス属性
#tasks
.task.red
/idの中に複数クラス
出力
test.html
<div id="tasks">
<div class="task red">
</div>
</div>
Author And Source
この問題について(Slimとは), 我々は、より多くの情報をここで見つけました https://qiita.com/one_punch_man/items/22bf64e00fdfbc39812d著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .