3
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.

twigでの文字連結

Posted at

毎回調べて忘れてしまう。

通常phpでは「.」を使って文字連結をするがtwigでは「~」を使う。
普段はLaravel使っているのでbladeも例として記載。

以下はhoge-※.svgを10まで表示するさせる例

<ul class="tw-flex">
    {% for i in range(1, 10) %}
      <li>
        //twig
        <img src="{{ asset('assets/icon/hoge-' ~loop.index~ '.svg','theme') }}" class="tw-block tw-m-auto sm:tw-m-0" alt="">

     //blade
        <img src="{{ asset('assets/icon/hoge-' .loop.index .'.svg','theme') }}" class="tw-block tw-m-auto sm:tw-m-0" alt="">
      </li>
    {% endfor %}
  </ul>
3
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
3
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?