V
V
Vadim Timoshenko2016-03-07 21:04:11
PHP
Vadim Timoshenko, 2016-03-07 21:04:11

How to display the views array in parts correctly?

I hang the site on the finished layout.
I'm theming views, and I have questions.
Layout in the form of columns. I display 9 news. They need to be arranged in 3 lines. So 3 news per line.
To split 9 news into 3 lines I use:

<?php foreach ($rows as $id => $row): ?>
<div class="four columns">
    <div class="item">  
        <?php
            $i++;
            print $row;
            if ($i == 3) {break;}
        ?>
    </div>
</div>
<?php endforeach; ?>

Unfortunately drupal doesn't like that (although it outputs everything by way).
Complains about Notice: Undefined variable: i in the include() function. Tried to prescribe var before i. Does not help. The site is down. As I understand it, this api drupal behaves like this. What to do?
Maybe there is some more humane way to display 9 news in 3 lines? Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2016-03-07
@PbI6A_KuT

It is worth simply initializing the variable $i = 0 before the loop, which will help to avoid the notice warning.

V
Viktor Bogutskii, 2016-09-02
@siteogra

In views, you can do such tasks without temming with separate templates. If you need to group something, use Global: Custom text according to this principle
For the fields that you display in the global field, set Exclude from display and there will be no duplication.
For example, this view outputs
I'm using bootstrap, so the table doesn't fit so use Format:HTML list. This will suit you better too, since you can set your own classes:
In extreme cases, you can make 3 displays in one view and define a step of 3 in the paginator.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question