I'm pretty new to any coding with views and am trying to create a filter that can sit in a block. This is for the Views calendar (although my question is related to the 'core' views module).
I am using this code:
<?php
$view = views_get_view('calendar');
$view->set_display('calendar_period_2');
$view->init_handlers();
$form_state = array(
'view' => $view,
'display' => $view->display_handler->display,
'method' => 'get',
'rerender' => TRUE,
'no_redirect' => TRUE,
);
$output = drupal_build_form('views_exposed_form', $form_state);
return $output;
?>In principle, this works fine, but I need to be able to dynamically set the display to match the current active display, so that it doesn't always default to 'calendar_period_2'.
So, what I need to know is whether there is a way to access the 'display' for the currently active view?
I know there is a views_get_page_view() method, but I don't know what I can do with this.
I'd appreciate any advice.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | screen.jpg | 109.8 KB | gmak |
Comments
Comment #1
merlinofchaos commentedWhat do you mean current display? There isn't a current display at any point in the code you link until a view is actually executed.
Comment #2
gmak commentedHmmm,
Maybe a screenshot will help explain (see attached).
The calendar view on the page has a 'display'. For example, the month display is
calendar_period_2. But if I switch to week view, this will becomecalendar_period_4.With the filter block that I have defined, I currently have the problem that the display name for the calendar is hard-coded. What I would like the filter block to be able to do is know which display is current in the calendar view, so that clicking the filter will not default back to some other view display.
Does that make sense? Is it possible?
Many thanks
Comment #3
gmak commentedI realise that I can 'expose' filters in a block and have done this, which gives me a whole set of blocks which correspond to the different 'displays'. The problem I've found is that I can't set these blocks to only appear when their corresponding 'display' is active.
If there is a way to do this, I could stop trying to figure out the above.
Is there some way of setting up some php for the block visibility that might be able to recognise which display is active?
My guess is that I need to parse the arguments, but I can't understand how to do this. The URL's look like this:
for month view (calendar_period_2) - http://example.com/calendar/2010-01?tid[0]=58
for week view (calendar_period_4) - http://example.com/calendar/2010-W01?tid[0]=58
for day view (calendar_period_3) - http://example.com/calendar/2009-12-28?tid[0]=58
in any of the above, the tid could be from none to 4 values based on the filter.
Again, any advice would be greatly appreciated.
Comment #4
esmerel commentedComment #5
dawehnershould do it.
Comment #7
MissterX commentedI got NULL.
This worked for me:
That is when I use it in a overriden theme file such as views-view-fields--page.tpl.php
$c_d contains the machine name while $current_display is the title I gave the page in the views UI.