2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

MiddlemanのSlimでmixin的なことをやる

Last updated at Posted at 2014-10-14

MiddlemanでSlimつかってるんですけど、jadeでいうところのmixinがないっぽいので、すごいつらい思いをしてました。

が、解決策を見つけたのでシェアさせていただきますね!

partialしつつ、localsで変数を渡してやる

呼び出し側

親.slim
h1 私が親です
div#hogehoge
  == partial "layouts/_child", locals: { hoge: 'この変数をpartialにお渡ししたいんです' }

呼ばれ側

child.slim
/ partialの _test.slim側
p = hoge

out.html
<h1>私が親です</h1>
<div id='hogehoge'>
  <p>この変数をpartialにお渡ししたいんです</p>
</div>

ちなみにpartialは入れ子もできる

child側でさらにpartialしてもちゃんと動く。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?