1

I'd like to create a complex view which combines several views. I'm using Views Infinite Scroll

The view logic:

  • view A row-1
  • view A row-2
  • view A row-3
  • view A row-4
  • view B Block 1
  • view A row-5
  • view A row-6
  • view A row-7
  • view A row-8
  • view B Block 2

    The difference between view B Block 1 and view B Block 2 is that Block 2 has offset from view B Block 1

    Ok the adequate minimum is to insert view B Block 1 to each n row of the view A.

    I tried to insert block in the view template but vainly.

    Please help!

    • I don't believe this is possible, but would love to see someone prove me wrong. The only way I see it, is to break them into different views with offsets, but you won't be able to use infinite scroll. – No Sssweat Feb 20 '16 at 20:10
    • Hey No Sssweat, i'm already using different spitted views and as you mentioned it's not cool – Errand Feb 20 '16 at 20:12
    • Can you check this link of OsTraining, where they have mentioned how to add other view as a field in the current view, check the last final image, you may get idea. Link – CodeNext Feb 20 '16 at 20:39
    • codenext, if i use views_field_view the view will be embed to each row. Of course i can render view like this and then hide all embed view except nth-child(5) rows... But this is not very cool too :) – Errand Feb 20 '16 at 21:09
    1

    this can be done by overriding your View's template for the Style Output plugin (e.g. views-view-unformatted--yourview_machine_name.tpl.php). Then in that template outputting something like this:

    <?php if (!empty($title)): ?>
      <h3><?php print $title; ?></h3>
    <?php endif; ?>
    <?php foreach ($rows as $id => $row): ?>
      <div<?php if ($classes_array[$id]) { print ' class="' . $classes_array[$id] .'"';  } ?>>
        <?php print $row; ?>
        <?php
          // this tells the view to do something after every 4 rows
          if (($id % 4) == 0):
          print views_embed_view('view_machine_name', 'block_1');
          } ?>
      </div>
    <?php endforeach; ?>
    

    If you wanted to alternate your secondary View's blocks - you could add some logic for that too.

    | improve this answer | |
    • this looks promising – No Sssweat Feb 21 '16 at 0:01
    • Thank you. So some reason it didn't work then i tried this last time. I inserted view in template and it shows up! Finally. Well it breaks the view with views_infinite_scroll but it is progress – Errand Feb 21 '16 at 9:09
    • 1
      @Errand , Infinite Scroll must be doing some custom preprocessing of the View's rows - look into that module's code and see how it grabs rows for dynamic loading. Also, the above approach works perfectly with Views Load More pager plugin. If it is not mandatory for you to use Infinite scroll, I'd say Views Load More can be a very good alternative. – oksana-c Feb 21 '16 at 15:05

    Your Answer

    By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

    Not the answer you're looking for? Browse other questions tagged or ask your own question.