0

I am trying to connect two different block views so as when you click the title of the first view block the second block will display the content of the url. Both views are of the same content type. How do i do this? or any usefull tutorials i can count on?

EDIT: I have this company news page which is accessible from the main menu so that's why i wont to keep the same url. So i created a content type called company news and two views. The first view will display the date and the title of the company new and the second view block will display the content of the company new clicked. My first view is like a left-hand side bar with the 10 newly added. So if a user clicks for example at the second company new the second view block willk display the content of that new. I hope i made it more clear!

4
  • Is it going to another page when you click the title? Commented Oct 8, 2012 at 10:25
  • Yes. But i wont to keep the page path the same!
    – paranod
    Commented Oct 8, 2012 at 10:31
  • At least your should pass it through the url so the second view can be based on that contextual filter. Please, explain how the page is done, what do you show, why you want to keep the same url etc... edit your question so is more understandable and you have more chance to find a solution. Commented Oct 8, 2012 at 10:35
  • I edited my question. I hope this is easier for understanding
    – paranod
    Commented Oct 8, 2012 at 11:01

1 Answer 1

1

In this case I think you need one view who shows title, date and body.

So now you will have a full list of all the news and through jquery you can do something like this.

 $('.field-name-body').hide(); //it hides all the body fields.
 $('.views-row').click( function() { // The body is a children of the row.
$('.field-name-body').hide(); // it hides all the open body fields if there is one.
  $(this).children('.field-name-body').show();
});

Do you want something like this? Fix the css with more specifications (view name, block name...) With the css you can do the style you want.


If you want to have two different blocks you need to show in one view all the title fields and in the other view all the body fields. You don't need contextual filter for the second view (a part from the company id). You will show all the body fields and then hide them.

Now you need to change the files views-view-unformatted.tpl copy it from views/theme, paste it into you template folder inside your theme and rename it with the name of the view. To find the name of that view, you have to open your view, on the third column you click on theme and you will see the files and the suggested name to specify that view (views-view-unformatted-YOURVIEW-BLOCK_1.tpl or something like this). Do it for both views block, they have to be different, one could finish with block_1 and the other with block_2. Clear the cache after you rename the files. In the views you can add the node id and exclude it from display.

This is views-view-unformatted.tpl

<?php if (!empty($title)): ?>
  <h3><?php print $title; ?></h3>
<?php endif; ?>
<?php foreach ($rows as $id => $row): ?>
  <div class="<?php print $classes_array[$id]; ?>">
    <?php print $row; ?>
  </div>
<?php endforeach; ?>

AND YOU CAN MODIFY ADDING THE ID IN THIS WAY WITH $view->result[$id]->nid;

<?php if (!empty($title)): ?>
  <h3><?php print $title; ?></h3>
<?php endif; ?>
<?php foreach ($rows as $id => $row): ?>
  <div class="<?php print $classes_array[$id]; ?>" id="<?php print $view->result[$id]->nid; ?>"> // in the body view use body-id 
    <?php print $row; ?>
  </div>
<?php endforeach; ?>

So, now again the js

$('.field-name-body').hide(); //it hides all the body fields.
$('.field-name-body:first').show(); // It will open the first news.
$('title:first').addClass('active');// add class active to the first title
$('.title').click( function() { // The body is a children of the row.
$('.title').removeClass('active'); // remove class active to all the title
    $('.field-name-body').hide(); // it hides all the open body fields if there is one.
    $(this).addClass('active'); //add class active to the clicked element
    var activeBody = $(this).attr('id'); //find the id of the clicked element
    $('#body-'+activeBody).show();
    });
2
  • I prefer to keep the two separate block because i already have the styling for two blocks and i dont like hiding elements. So am i adding the nid to the fields of the two views. And then ? I have to add a contexual filter for the second block? Am confused!!
    – paranod
    Commented Oct 8, 2012 at 11:32
  • Paranod, let me edit my answer. I'm having lunch now. I will tell you everything step by step. Anyway with this method you will always hide the contents, will work as tab. Commented Oct 8, 2012 at 11:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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