K
K
kranopodem2016-06-03 06:23:54
Android
kranopodem, 2016-06-03 06:23:54

yii2 listview. How to insert a block after every 3rd element (item)?

Can you tell me how to make it possible to insert a block through every 3rd element. The picture shows where it should be. How can I do it? Thanks in advance.
cd2a6c5a7a3f4e6582399d047d11720b.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
bearenok, 2016-06-03
@kranopodem

<?= ListView::widget([
        'dataProvider' => $dataProvider,
        'itemOptions' => ['tag' => false],
     //'itemView' => '_teaser',
        'itemView' => function ($model, $key, $index, $widget) {
            return $this->render('_teaser', [
                'model' => $model,
                'key' => $key,
                'index' => $index,
                'widget' => $widget,
            ]);
        }
    ]) ?>

in '_teaser.php' $index can be processed
<div class="item" data-key="<?=$model->id?>">
...
</div>

<?php if (($index+1) % 3 == 0) : ?>
я после третьего?
<?php endif; ?>

X
Xurshidbek, 2018-07-30
@Xurshidbek

Super works!! Automatic close!!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question