I have an exposed data filter with only the year granularity. If a user selects a particular year in the exposed filter, I would like to display that year in the title or header. For example is a user selects the year 2009, I would like to use "2009" as part of the header of that page.
I'm not sure I understand how arguments work for exposed filters. It appears as thought they are not the same as regular drupal arguments.
Looking at the url of the exposed filter I guessed at the following. Don't know if i'm even remotely close.
<?php
$new_var = $view-> date_filter[value][year];
print $new_var;
?>
Any ideas?
Thank you for any help.
Comments
Comment #1
akolahi commentedI forgot to mention I'm exposing filter to block
Comment #2
dawehnerI think the following code could work
Comment #3
akolahi commentedThank you.
For some reason that was giving me a white screen error. instead i tried the below and got the word 'Array' outputted.
Comment #4
dagmarTo use dsm() you need the devel module.
Comment #5
akolahi commentedThat's a beautiful thing!! Many thanks!!
Comment #6
akolahi commentedComment #8
sapark commentedThanks! Also works with a select list of node-referenced years as a Views argument.
Add year argument,
Add %1 as title to use when argument is present,
Provide default argument,
Default argument type: PHP code
Comment #9
twistedindustries commentedCan someone be more specific with this code, I have tried every combination and cannot get it to work. Maybe a generic sample of this could would help.
Comment #10
twistedindustries commentedChanging status
Comment #11
dagmarDescriptions of the Priority and Status values can be found in the Issue queue handbook.
Comment #12
dawehner@twistedindustries
I does not help you if you post the think to different issues. People helping here are just mans, so they might wait to answer your question if you put the same more then one time.
Comment #13
shushu commentedSince useful for my needs, I guess it can be for others.
Here is a small module that do it nicely, with themeing enabled.
http://drupal.org/project/exposed_filter_data
Comments are welcome
Comment #14
bfr commented@9 Use print_r to find out what data your array contains:
Comment #15
cancerian7 commentedMany Thanks.
Comment #16
dagmarOk, I think this is already fixed.
Comment #18
iamjon commentedMarked #707710: Display exposed filter values in view header or on page (snippet? attachment? configuration?) as a duplicate
Comment #19
joetsuihk commentedremember to check_plain($view->exposed_input[date_filter][value][year]);
Comment #20
scott859 commentedGreetings,
I'm having a similar issue. I have a view that has a number of exposed filters and I wish to list what filter criteria is being used in the header.
Using the following code in the header:
I get a print out of the data in the array (see attached screenshot).
My issue is that the first field, labeled "Location Code" is a node reference, and as you can see from the screen-shot the array is listing the value of the selected item(s) rather than the label (the title of the node).
If anyone can give any insight into printing the label (or title) of the node reference item(s) selected, rather than the value, I would appreciate it.
Thank you,
Scott
Comment #21
joetsuihk commentedre #20
try
my blog post about this: http://joetsuihk.com/%E6%9F%A5%E6%89%BE%E4%B8%80%E5%80%8B%E9%81%B8%E5%96...
Comment #22
scott859 commented@joetsuihk
Thanks so much, that was a big help.
Thanks again,
Scott
Comment #23
ayalon commentedHere is an example that also works with Views 3:
Comment #24
tribe_of_dan commentedThis post took me ages to find and helped me greatly. Thanks! :)
Comment #25
Anonymous (not verified) commentedWould #23 work in Drupal 7?
Is this handled any differently?
The module provided hasn't been ported yet.
Thanks,
Drew
Comment #26
TimelessDomain commentedhttp://drupal.org/project/exposed_filter_data
Comment #27
chrisdomingo commentedhello guys..
i used this snippet:
it worked on my view, however it displays error messages.
any info about this is greatly appreciated! ^^
Comment #28
bfr commentedYou need to use quotes(' or ") when your array keys are strings:
For more help, please paste your whole code, the error is speaking of "line 6" and you are showing only two lines.
Comment #29
chrisdomingo commentedthank you bfr. It worked. i thought that the value passed on the filter is still an integer, never thought of it as string... :)
Comment #30
TravisJohnston commented+1
Comment #31
vvs commentedI use data from GET for display as title:
Comment #32
museumboy commentedOk, I'm putting this out there because it worked for me. I added this code to the header of my block view.
the field name that you are sorting is defined in the Better Exposed Filter settings (if you're using that). I kept trying field_release_date and that wasn't working. I needed to use field_release_date_value. I'm not getting any errors with this code.
Comment #33
terracoders commentedI'm not really a PHP kinda guy, but I'm also throwing this out there for anyone who finds it useful. I needed to get custom text in the view header based on taxonomy term from which the view filters results. Like Museumboy above, I pulled the field name from Better Exposed Filters (term_node_tid_depth) and used it to get taxonomy term ID. Based on the term ID (numerical value) I put together a custom header. The code might be a little redundant (again, PHP not my strength), but it was an easy fix for custom headers. You would, of course, need to adjust the numerical TID values to match your own use case.