Different Views inside a Custom Block in Drupal 7 - drupal

I have defined a Custom Block in my module and I want display different views in that block when user selects different sections using navigation menu. With the use of hook_block_view() i can set the content that needs to be rendered for that particular block. But how can I render different views based on the user's selection?
For a example;
I have a Block called Customers;
When user selects the Customer List form navigation menu, I want to show a customer list inside Customers Block.
When user selects a Specific Customer, I want to show the detail of that customer inside Customers Block.
What would be the best approach to achieve this in Drupal 7?

You can define your block from a code and use any logic you want to decide which view to use (simple if or switch php statement). Then you can embed different view based on your logic:
https://api.drupal.org/api/views/views.module/function/views_embed_view/7
Or you can get view results and prent data on your own:
https://api.drupal.org/api/views/views.module/function/views_get_view_result/7
Or, you can make 2 different block views and set for each one on what pages to be visible. You can do that in block settings or for more complex logic you can use context module to place appropriate block to a region depending on situation (page, what ever).

Related

Is there a drupal 7 module to change/filter content in a view via tabs that are not placed inside of the view?

I have a library page with some taxonomy topics(resource types) that are currently being filtered by some really hacky tabs that I would like to replace to do two things:
1) get new, more user friendly tabs, with the capability to be placed outside of the view yet change content inside the said view.
2) be able to have the tabs grouped together in a way I can manipulate them with css.
I am fairly new to the drupal world. What would you suggest? Thanks!
Do you use exposed filter options?
If so in the advanced tab of the view you have a option 'Exposed form in block' this way your exposed filters will be placed in a seperate block.
After saving the view you have to enable the block

Two Blocks for sort filter Views — Drupal 7

I have a view in Drupal 7 with results including a field of date and another with price, I need to sort the results by means of these two fields when I click on the appropriate link (not button or dropbox radio), but the trick is I need add the different sort filter into two separate blocks, because each block will have a different per user context.
Besides the filters should be links. Any idea how to work this?
You can have different displays for all order variations and then use appropriate one depending on parameter passed with link. Of course, you can't just use block view, but create your custom block which will embed correct view depending on that parameter.
Other way would be altering view query. In you module add hook function for altering view and inside you should detect your view, check for parameter and alter order value.
You can create two block displays for the same view, each of them sorting the results with a different criteria. Once both blocks are created, enable them in the same theme region and establish the URLs in which each module should be displayed. This configuration can be set using the block configuration form.

Concatenating 3 views in one page

how could I concatenate 3 views in one page ?
Should I use blocks ?
You can use blocks, but Views provides an attachment display as well. Attachment displays can be attached other other displays within the view. So, you could create your base view, then create an attachment display that attaches to the base view, and then create a second attachment display which attaches to the first attachment display.
Attachment displays are good if each view is really just another way to view the same query (like, a summary view and a detail view). But if you wanted to combine three disparate views, blocks would be the way to go. Either create a block display for each view and add them to the same region in Site Building -> Blocks, or create a page display for one of the views and block displays for the other two.
A third option would be to use View Reference, which lets you reference views as CCK fields, if you needed the views to part of a node.
It probably depends on your layout.
if you want to embed a view in somewhere else besides your block regions, you could try the embed views module I also believe the the panels module has a much more dynamic way of rendering multiple views on the page (but flexibility also adds some to the complexity)

display a 'view' list within a composite layout in drupal

I've installed the composite layout module and I created a view with a list of 'testomonials'(just a simple list of title and excerpt).
On my front page, I have been able to include a couple of other nodes within that page and a couple of blocks (e.g. within then same composite layout). However, I want to also include the list view of the testimonials (I want to display the whole list and then use javascript to manipulate it).
So my question is, is it possible to include a view list inside a composite layout and if not how would I take my front drupal page and include a node AND say my list of testimonials
Thanks
Andy
If you are talking about a views module view, you can turn that into a block by adding a display of type block to it (on the views configuration page). Once you saved that, it will be available as any other block on the blocks configuration page.

Drupal: How to show specific view in a particular block

Let's suppose I have created a view that shows some kind of stories.
But I want to show this view in a left-hand bar — not a link to the view, but the view itself.
How can I connect my new view with a fixed block position?
I want to be able to show real view data in various places on my page.
Is it possible or I am limited only to central area and links to views from menu?
Using Views 2.x for Drupal 6.x it's simple to create a block from a view. Every view has a set of 'default' settings and some number of display settings. A display can be a page, a block, a feed or anything else that creative module authors.
To make a block from your view, you just "Add Display" of type "block", override any settings that you want changed in the block (IE - display less items, just a node title, whatever). You then have a block that you can place like any other Drupal block.
edit: Answer to "Can you limit stories to ones that are tagged"? Sure thing. You just add a filter for Taxonomy terms.
Getting a view to display in a block is easy. Once you have created a view and assigned the view as a block position you simply head to blocks in your admin and you'll see the view.
Just select the block and save it. Simple.
If your view doesn't show, check your filters and that the view fields are correct. Usually if they are not showing it is something simple like selecting content published = yes.
You can create views as pages or blocks. As you're not telling exactly which Drupal/Views version you're working with, all I can tell so far is that, after you create the view, you can tell it to display as a block or as a page.
Then go to the blocks settings and set that to the position you want.

Resources