1
1

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.

PhoenixFramework + Slimでインデックス付きのループをする方法

Posted at

状況

Listの*番目で違うclassをあてたい。というケースでListのindexをどうやって取るのか?というのを考えたのでメモ。

環境

Elixir 1.3.1
PhoenixFramework 1.2.0
slime 0.14.0

解決方法

該当のListのカウントを保持し、それを最大値としたRangeを作成して、Rangeをループさせる

- comments_count = Enum.count(@comments)
= for i <- 0..(comments_count - 1) do
  = if i < 3 do
    do something...
  - else
    do something...

まとめ

やりたいことは実現できているもののどうもすっきりしないので、引き続き良い方法は模索していきたい。case文使いたい!などちょっとテンプレート周りではモヤモヤが多いので、調べてわかったらQiita上にアップしていく。

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?