LoginSignup
0
0

More than 5 years have passed since last update.

eZ Publish で子アイテムを2列に並べたい時のテンプレート処理

Last updated at Posted at 2017-02-03

eZ Publish 4.x/5.x Legacy で子アイテムを2個単位でグルーピングしたい時のテンプレート処理。

テンプレートの記述例

<div class="level-1">
{foreach $node.children as $key => $child}
{if eq( $key|mod( 2 ), 0 )}

  <div class="level-2">
{/if}

    <div class="level-3">{$child.name|wash()}</div>
{if or( ne( $key|mod( 2 ), 0 ), eq( $key, $category.children_count|dec ) )}

  </div>
{/if}
{/foreach}
</div>

出力 HTML

<div class="level-1">
  <div class="level-2">
    <div class="level-3">アイテム1</div>
    <div class="level-3">アイテム2</div>
  </div>
  <div class="level-2">
    <div class="level-3">アイテム3</div>
    <div class="level-3">アイテム4</div>
  </div>
  <div class="level-2">
    <div class="level-3">アイテム5</div>
  </div>
</div>

解説

子アイテムを {foreach} でループし、キーが偶数ならヘッダー処理、奇数か最後尾ならフッター処理、という流れになっている。
最後尾の判定は、子アイテムの数を $node オブジェクトの children_count 属性から取得して、dec オペレーターでデクリメントした値を使っている。

リファレンス

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