文字列省略(Twig1.6以降)
| 1 2 | {{# 32文字目まで表示して残りは...にする #}} {{ name | length > 32 ? name | slice(0, 32) ~ '…' : name }} | 
HTML参照文字エスケープ
| 1 2 3 | {{ html | e }} {{# または、#}} {{ html | e("html") }} | 
リプレース
| 1 2 3 | {{ "I like %this% and %that%." | replace({'%this%': foo, '%that%': "bar"}) }} {{ "I like this and --that--." | replace({'this': foo, '--that--': "bar"}) }} | 
改行文字をbrに
| 1 | {{ text | nl2br }} | 
ループ
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | {## 基本形 ##} {% for Product in Products %}   ID:      {{ Product.id }}   Name: {{ Product.name }} {% endfor %} {## キーだけ表示 ##} {% for Product in Products | keys %}   key: {{ Product }} {% endfor %} {## キー,値をそれぞれ取得 ##} {% for ProductKey, ProductValue in Products %}   key:   {{ ProductKey }}   value: {{ ProductValue }} {% endfor %} {## sliceと組み合わせたり ##} {% for key, value in ['太郎', '次郎', '三郎', '四郎', '五郎']|slice(2, 4) %}     {{ key }}:{{ value }} {% endfor %} {# 0:三郎 1:四郎 2:五郎 #} | 
ループの中で使える便利なやつ
| 1 2 3 4 5 6 7 | {## loop.lastは、最後の要素の時true ##} {% for Product in Products %}   ID:      {{ Product.id }}   Name: {{ Product.name }}   {## 最後の要素じゃなかったらコンマ出力 ##}   {{ loop.last ? '' : ',' }} {% endfor %} | 
正規表現マッチング
| 1 2 3 4 5 6 7 8 9 10 11 12 13 | {# 基本形 #} {% if Product matches '{^abc$}' %}   match! {% else %}   not match!  {% endif %} {# メタ文字(.や?など)エスケープ時はバックスラッシュ3つ #} {% if Product matches '{\\\?id=1234}' %}   match! {% else %}   not match! {% endif %} | 
その他は随時更新。
参考URL)
- https://hrroct.hatenablog.com/entry/2017/04/28/184032
- https://qiita.com/assa/items/4fef2f3abd95248ed626
- https://twig.symfony.com/doc/2.x/filters/replace.html
- https://tetra-themes.com/eccube3-dump-498/
- http://www.tomcky.net/entry/2018/02/08/010639
- http://mononofu.hatenablog.com/entry/20111209/1323431291