I want to start compiling a views FAQ.
There are LOTS of frequently asked questions, and particularly in the areas of HOWTO. One of the problems I have, as a person, is that I need this data to be compiled before I can act on it. Therefore, I'm asking people to help me out a bit.
Please, comment here with common questions (and answers if you have them, but they are not as necessary). Give links if there's an intricate discussion involved.
With Views it's pretty easy to build a simple FAQ engine just with taxonomy, so that's going to be one of the first FAQs. The only additional piece that I think is needed is weighting, and I believe weight.module will do that without any fuss or muss. I'll probably host the FAQ on angrydonuts but I may ask Moshe's permission to host the FAQ here, so that it's closer to Drupal.

Comments
I'm definitely game to help w/ this...
As you know, I still owe you Views documentation from months back. :(
Here are some ideas. I haven't fleshed any of these out yet because I'm brainstorming, but maybe this could be a starting point.
General
What is the Views module?
You might think this is a silly question; but I mentioned once on one of the Lullabot podcasts that Views was, in essence, a dynamic query-builder, and after that got like 3-4 people PMing me on IRC saying "THANK YOU!! I had heard so much about this 'Views' thing but I didn't know what it was, and now I played with it and I love it!" You could also use a simpler definition of "Use a View whenever you need a 'list of stuff'" although that's getting to be less and less true now that there are more powerful Views modules out there like Calendar.
How can Views make my life easier?
Provide an overview (maybe linking to some examples) of some different use cases; for instance, you can use it to setup additional content administration tools, you can use it to create a more robust "tracker", you can use it to override menus and provide your own listing, you can use it for X, Y, Z and the other thing.
What are some other modules I can use in conjunction with Views?
Mention things like CCK and its modules, Views Bonus Pack, Viewsedit (or whatever that was called), etc. along with a brief description of what they do.
Using Views
Why would I want to use arguments as opposed to filters?
basically, that arguments can be dynamic, while filters are "fixed"
What is Argument Handling Code used for?
Maybe a pointer off to http://drupal.org/node/70145 (assuming that's still accurate)
Troubleshooting
Why is my View showing unpubished nodes?
A: you need to add "node status is published" to your list of filter criteria.
Why does my breadcrumb read %arg?
A: If you want a dynamic title, this should be moved to the argument section.
I'm user 1. Why can't I see my view?
A: When the View is restricted by role, that trumps user 1 access. Make sure user 1 is added to at least one role that can see the View. (note: is this a bug or by design?)
Views for Developers
How do I Views-enable my module?
(likely this needs to be broken down into different use cases... i.e. "How do I provide an additional field to Views module from my module?" etc. This is a part I'm not that familiar with yet, so am not sure how best to break it down...)
What hooks does Views module provide for my module?
I heard tell of a views_query_alter? any others?
Are there plans to put Views in core? If so, what can I as a developer do to help this along?
Here's a FAQ from me. ;)
Instantiated? ;-)
So, did this Views FAQ or Views Documentation ever get actually built someplace, other than in this comment string?
..chrisxj
(who has a hard time keeping up with all things Drupal...)
I'm in
You've got my help, Earl. Here's one I could write up: "How do I show a random image/node in a block?" (Clients seem to like random rotating things. It looks cool. :-) )
Also, something I think could help a Views HowTo/FAQ is sample builds. Views has a nice import/export feature. If a how-to included an export of a view that does what's being described, then it could read "import this and follow along, then modify as needed". While that wouldn't work as well for template tricks, it could help a lot for Views configuration.
Awesome. Put stuff here and
Awesome. Put stuff here and as information accretes, I will try to compile it.
Theming
I've been battling all day with Views in conjunction with CCK and solved my immediate problem by shifting all theming related tasks to CCK, since I just couldn't get it to work in Views. So now I just use it to do some simple filtering, which works fine.
My immediate question would be whether Views allows to purely theme with .tpl.php files in PHPtemplate, which I find by far the easiest way to get quick results. I read the whole handbook and it all seemed to make sense until I arrived at the theme chapter. The comments and discussion suggested that there was a fair bit of confusion.
I would also like to know about recommendations on using CCK and Views together, since I assume there is a fair bit of overlap between the 2 - that might be incorrect, but it was my first impression.
I will spend more time with it over the next few weeks and am happy to leave all my findings/frustrations/enlightenments here.
How about a Wiki approach to this?
Oh, and one more thing merlin...can you tell me how I get rid of all the DIVs that Views wraps around, say, block content?
Many thanks...
There is, in fact, no
There is, in fact, no overlap at all between CCK and Views, to be honest. CCK handles the storage and presentation of a single node. Views handles how you choose a group of nodes and present them. They complement each other very well, which is one reason you often hear "CCK & Views" in the same sentence.
The views theme wizard will help you generate a .tpl.php file for List type views, which is probably the most needed theming tool in Views. A distant second is probably table views, which could also use some theming help. And theming a teaser view is actually so ludicrously easy it's not funny.
Does Views support comments?
Can I create a list of recent comments/forum replies with Views?
If yes: How?
If no: Why not? (...because a comment is not a node?)
Answer: Yes. Views 1.1 comes
Answer: Yes. Views 1.1 comes with a basic recent comments block [that needs theming to look nice].
IMPORTANT
merlinofchaos - I was trying to find why this feature wasn't available to me and then updated to the 1.4 version and then sat there starting at it for a little while.
I believe it's related to the IMPORTANT-IMPORTANT note in the README.txt that I was ignoring:
Would that make sense?
--
Knaddison Family | mmm Beta Burritos
knaddison blog | Morris Animal Foundation
Views and multimedia
I'm really excited about what's starting to happen with views and things like playlists, the audio module, and even podcasting and video. http://www.angrydonuts.com/audio_playlists_in_a_flash_playe
http://drupal.org/node/93968
Once we get things a bit more figured out (I'll help in any low-level development/testing way I can), some howtos/tutorials about integrating views, audio, and some other modules to do create things like...
...think that would be pretty useful and powerful!
Gus Austin
Views iTunes Smart Play List
Can you build a new view in a similar way to building a new smart play list in iTunes?
I've never used itunes so I
I've never used itunes so I can't answer that, myself.
Potentially more powerful than smart playlists?!?
Here's some info on smart playlists, Merlin:
http://www.apple.com/lae/itunes/smartplaylists.html
http://www.andybudd.com/archives/2005/08/itunes_smart_playlists/index.php
http://www.43folders.com/2006/11/09/music-only-playlists/
The views bonus pack enables you to filter on the audio type (title, artist, genre, year, album). Lay some other filters on top of that and I think you can create some wicked smart playlists!
Gus Austin
Would love to create a Views Search Block
The feature I would really love to build is a Views Search Block that is just the filters with a submit button that takes you to a page showing the results. The idea being similar to a used car website where you have a block:
Make ______
Model ______
Price ______
-- Submit
So far I have not had any luck. The closest I've come to a solution is the suggestion manually code a block.
Re: Would love to create a Views Search Block
I'd like to have this also. When you say you "have not had any luck", did you try to write a custom module? Or did you just try to configure views? Our client ran past budget money before I could get to it. Any chance of a bounty on this one?
Doug Green
www.douggreenconsulting.com
www.dougjgreen.com
Like this?
http://www.angrydonuts.com/displaying_views_exposed_filters
Oddly enough, your question turned out to be appropriate for the FAQ because it actually does exist; but the FAQ isn't for feature requests, so you asked it incorrectly.
Table formatting and potential module solution
I checked the forum yesterday and found no solution, so I wrote a simple module for moving the views filter form to a block, only to finish it and notice that maybe I didn't have to write the module because you posted a FAQ today. However, when I followed your example, if I have multiple exposed filters, they still are displayed in a table in my block and the block is way too long. Do you see any use for the following module that uses javascript to recreate the form without the table and reposition the form in the block?
http://cvs.drupal.org/viewcvs/drupal/contributions/modules/views_filterb...
Doug Green
www.douggreenconsulting.com
www.dougjgreen.com
Override the theme function
I don't have the code for it in front of me at the moment (it's at work, I'm not), but if you provide an empty theme function for the filter form then it will format in the "usual" way, that is, linearly down. I found that worked perfectly for a filter block.
views_filterblock module
See http://drupal.org/project/views_filterblock
You can do this with some code, as merlin points out above and for example, see Displaying Views Exposed Filters in a Block. But I wrote a module that simplifies the process so no coding or theming is required.
Doug Green
www.douggreenconsulting.com
www.dougjgreen.com
Unrequired $args
Here's one that just ate a few hours of my life:
If you're creating a page view that can take arguments at the end of it, do NOT put $arg at the end of the path unless you wish them to be required. For example, a path of:
views/myview/$arg/$arg
Will result in page-not-found for views/myview/$arg, even if you have the arguments set to "show al values". That's because Drupal will not even match the page up to a View, and therefore the Vie won't even be called. If you want arguments at the end of the path, simply do not list them in the URL field under the Page fieldset. Only use $arg for place holders in the middle of the URL.
(This is with Drupal 4.7 and Views 1.1. I think it could actually be done as a UI patch to clean up the language on the form.)
Issue submitted
I've submitted an issue to clarify the language a bit.
Here's a good entry for the FAQ....
argument is shown as %1 in breadcrumbs -- I remember being screwed up by this before too.
Two more common FAQ
Two more common FAQ entries:
How do I print a block of a user's posts on their profile page: http://drupal.org/node/111639
How do I have a view that contains posts within the last XXX time period: http://drupal.org/node/111550
How to display a default
How to display a default exposed Views filter in top of search result?
Filter could sort results as per any of the following criteria:
Relevance, Activity, Rank, Registered, Updated, # of Views
What I'm really wondering is
What I'm really wondering is whether there's any documentation re plugins, and whether it would make sense to put any info on that in the FAQ.
Jakob Persson – Leancept – Results-only digital and marketing consultants – Personal blog
Removing Views CSS (with Panels)
Panels combined with views is very powerful. It allows you to create pretty much just about any type of front section page you could want based upon the content in your site.
However, there is one problem that always plagues my when I use this dynamite duo (note when i use it is usually in a 3 col stacked arrangement or some other column heavy panel config): It's that the themed output always gets bunched together and requires css tweaking to get it to look the way i want.
Tweaking the css isn't my concern. I'm adept enough to do that and willing to!
The problem is that the output generated by the combination of panels with views embedded in the various regions results in what appears to be about 10x too many unnecessary div wrappers around the needed content. I'm sure those divs exist because the code is highly automated and can't account for every living incarnation someone is going to use it for.
But the multitude of nested divs makes it extremely hard for even an advanced css themer to target the margins/padding on all of the divs to get the panel to look the right way in the page. That's even with using firebug and web developer plugins! I'm not sure how anybody would tackle this without those. All the time you save generating the panel with the views seems to be wasted trying to theme it adequately. In fact, i'm starting to wonder if it actually takes longer using this combination versus simply inserting sql queries where i want them with only the necessary divs required.
I would prefer not go that manual route since the panels/views infrastructure is so capable.
So i'm wondering if there is a way to eliminate the extraneous divs that are being created by views by overriding the theme functions that generate the divs? I'm sure there is a way but i'm having trouble digging through the modules to find where they live and what they are called.
fwiw, the majority of views i embed in a panel are block views. So wherever the block view theme function lives that's the one i want.
Also, my last panel was a 3 column stacked that included a 2 column bonus pack block teaser view in the top panel of the 3 column panel. It's kind of like view inside a panel inside a panel. I'm still scratching my head trying to dig through all the divs generated to get that layed out correctly. :-)
So where are the bonus pack theme functions that generate the divs for the embedded block?
Basically:
1) what's the best method to approach this
And preferably one that emphasizes reusability so that every time i create a panel i don't have to start from square one again.
I'm wondering if i can separate out the views css into my theme directory, customize it and then reuse (copy into my other sites that use panel based on teh same theme). that way i don't have to start from scratch every time i use panels on a new site. because the views/panels css is isolated i can simply drop that in each new installation.
2) Even better and or in addition to #1 would be to override the views block (and other theme functions) that generate the extra divs. That makes the page source look manageable, clean and more accurately semantic
3) Finally, I would say at least a third of divs are probably being generated by the panels module. So it's not all a views issue. I just thought that because views and panels are so tigthly integrated and under merlin's domain, that some suggestions might be offered for streamlining the panel div output here as well.
thanks for any and all info you can provide
Use regions instead
newdru:
As far as I understand, the short answer to your question would be to use regions in your page instead of panels. Since you have absolute control of the HTML in page.tpl.php, you can limit the number of divs used. Then you just insert into each region either the content of a block or the result of a view.
Admittedly, you lose flexibility, but that's the price to pay.
Cheers.
If you see my post above..
I'm not sure regions would exactly fix the problem for a case where you have a view that uses a view type of for example 2col teasers because they essentially go back to using panels to theme and generate output.
The net result is even if you manually insert the view block, you're still going to pull the extra stuff in. unless i'm missing something.
It would seem like the only fullproof way would be to hardcode sql querries versus use views and just theme the output yourself. Definitely an option but not leveraging the power of either views or panels.
thanks for your input
If you see my post above..
I'm not sure regions would exactly fix the problem for a case where you have a view that uses a view type of for example 2col teasers because they essentially go back to using panels to theme and generate output.
The net result is even if you manually insert the view block, you're still going to pull the extra stuff in. unless i'm missing something.
It would seem like the only fullproof way would be to hardcode sql querries versus use views and just theme the output yourself. Definitely an option but not leveraging the power of either views or panels.
thanks for your input
Oh! Now that I read some of
Oh! Now that I read some of your reasoning, your problem isn't the number of divs, it's a bug in Panels CSS that is adding padding to arbitrary divs incorrectly.
In your css, fix the 'div div' thing that's giving lots of extra padding to every div and your problems should ease up some. That's something stupid I did without fully understanding the impact it would have on the CSS.
Uhm...
Ok.. i tried your quick fix suggestion and came up with a few things.
fwiw, i'm using panels version 1.1.
PART 1
According to the panels readme, I can copy the necessary panels css files:
panels/layout/twocol.css --> that's for the embedded block panel view in the top panelpanels/layout/threecol_25_50_25_stacked.css
to my themes folder:
/sites/dl51.com/themes/blackmarine/ (yes my theme is called BLACKmarine - no typo)and override them there.
However, when i look at my page source for the panel, the files are still being pulled from the panels module directory and not my theme directory:
<style type="text/css" media="all">@import "/sites/all/modules/panels/layouts/twocol.css";</style><style type="text/css" media="all">@import "/sites/all/modules/panels/layouts/threecol_25_50_25_stacked.css";</style>
<style type="text/css" media="all">@import "/sites/dl51.com/themes/blackmarine/style.css";</style>
Q1) So either i'm doing something wrong or the panels readme is incorrect. which is it?
It would be great to NOT have to overwrite the panels code NOR clutter up my style.css with panels stuff. Overwiting becomes a problem when you use multisite and share panels. Cluttering up my styles.css makes for hard to maintain styles.
PART 2
directly changing the only "div div" line in the actual panels (not my theme) css files did actually correct the squashing of the embedded 2 column views per:
.panel-3col-stacked div div {
margin: .5em;
margin: 0 !important;
padding: 0 !important;
}
However,
a) i actually get slightly different results if i don't use !important which is kind of odd since i'm not overriding this anywhere else that i know of?!
Two major problems:
b) Although this allows my views blocks to sit in the top panel ok (not be squashed), the minute i try to start adding margins or padding back in to make them look good (not butted up against eachother), they immediately drop to down due to the float property not having enough space?
c) Because there are myriads of nested divs, trying to match the color up of all the divs to a unified background is extremely hard, you literally have to keep adding bg color props to every single div to combat the problem
(see part 3 below - basically all the extra divs make spacing and coloring difficult per b/c above)
PART 3
Actually, this "div div" thing doesn't really solve the problem. It's kind of a hack for poorly designed css. I hate to say that because I know you've worked hard and long on panels/views. And i'll be the first to say that it rocks and makes life extremely easy for a lot of drupalers. The real problem is that panels/views generates way too many unnecessary divs.
Let me show and ask you again.
Here is the div structure for the first the top pane of a 3 col stacked panel with an ebmedded 2 column teaser:
<div id="homepage" class="panel-3col-stacked"><div class="panel-col-top">
#<div>
#<div id="block-views-frontpage" class="block block-views">
#<div class="content">
#<div class="view view-frontpage">
#<div class="view-content view-content-frontpage">
<div class="panel-2col">
NOTE: this is where the actual 2 column teaser display (more divs) actually starts getting inserted . e.g. meaningful content - everything up to this point serves no function - unless i'm missing something!
</div>
<br class="panel-clearer"/>
</div>
</div>
</div>
</div>
</div>
</div
Note: in that structure all of the divs with poundsigns are completely unnecessary.. and i think there are a few more laying around that i didn't bother to post. Each carries it's own margins and bg color settings. They load the page down and make it hard to maintain. I imagine even though you developed this code, it's probably hard to get a hold of what's going on there - yes?
So:
1) Why are these divs generated? and why can't we just cut them out?
2) Where are they generated? - That's more important -especially for bonus pack view types that point back to panels. I want to see if there is a way to remove the divs at the source in the theme / function level! I'll at least give it a shot!
3) NOTE that even if you apply the "div div" fix, everyone of those unnecessary divs has a margin/padding / background color setting of it's own which completely throws off the alignment and look of the nested panes in the panels to try to give the panel a unified look. They all have to be zeroed out!
4) Even if i create regions and avoid using panels, I'm still going to get those extra divs because they're generated by views or views using panels (in the case of a block view that embeds a 2col teaser)
5) also, i grep'd the views files looking for block + theme lines but couldn't find any. where in your modules are the blocks created?
Sorry for the questions but i'd actually like to try and figure out a better way to do this if it's possible.
thanks for you help.
I'm really, really, really
I'm really, really, really tired of people callin the divs that Views puts in unnecessary. At one point I did a walk-through of the stuff Views puts in and everything is there for maximum flexibility, and are necessary for some uses. I found one div that may be superfluous.
You've got a panel inside a view inside a panel. Of course you're going to have a bunch of divs, they're all trying to do stuff.
And there's no single place that "all those divs" are being put in. Panels puts in divs from the layout, so you've got 2 layouts coming in. Views puts in divs from its theming functions. Each block puts in a div. I really don't know what to tell you. You can reduce the divs that Views puts in by theming the view.
As for part the panels override, you have to preserve the directory structure, so your CSS file needs to be in themes/blackmarine/layout/whatever.css
So anyway. I don't really know what to tell you. Everything there is themable. Go theme it.
Debug output for Views arguments
For me,
print arg(1);didn't work, nor didwatchdog('debug', arg(1));, but (thanks to merlinofchaos for pointing me to this obvious one)drupal_set_message(arg(1));does work!This can be very useful in debugging your "Argument Handling Code".
Here's another good FAQ
Here's another good FAQ entry: http://drupal.org/node/133775 (how to put a view in a book outline)
Another FAQ entry:
Another FAQ entry: http://drupal.org/node/137898#comment-224760
Not sure if it's a feature
Not sure if it's a feature request or a FAQ, but seen it a couple of times in the forums and wondered myself.
If I set up an argument with taxonomy term name, and my taxonomy term has spaces in it, I get a url like example.com/view/taxonomy%20term can I get it to work with example.com/view/taxonomy-term instead using argument handling code?
edit: prompted by this forum thread, which just got an answer: http://drupal.org/node/140478
An easier option might be
An easier option might be simply to replace spaces by '+' symbols in your link generating code i.e.: example.com/view/taxonomy+term
- the +'s are converted into spaces for you.
The only issue with that is
The only issue with that is I have pathauto set up doing /tags/taxonomy-term, then views per content type generating /news/tags/taxonomy-term history/tags/taxonomy-term (although it's obviously news/tags/taxonomy%20term at the moment) etc. My interest in it is more about consistency than hatred of the %20 ;)
I'd like to re-iterate that
I'd like to re-iterate that this thread is for posting FAQ issues that already have answers. It's not a thread for asking questions, that dilutes the value of what is here.
sorry, my bad. Actually,
sorry, my bad. Actually, while we're on this point, I end up answering about 30% of support forum questions with some variation of "you can use the views module for that" - do you want "yes you can do that, here's how" answers in the FAQ to those general questions that don't start off being about views, or are those really handbook pages pages?
Actually I'll answer it myself by checking the views docs and trying to put some in where I think they're missing.
It's a little difficult to
It's a little difficult to say; for the simpler ones, it definitely belongs in the FAQ. For the more complex ones, probably in the Views Snippets section. The trouble there is that the snippets section isn't really organized and the FAQ (when I ever get around toa ctually putting it together) will be.
How to pass multiple arguments as one value?
How can I use a syntax like taxonomy's one, to pass multiple values to one argument?
This does not work if the numbers are not term ids:
http://example.com/view_url/23,76
A question regarding complex Views
Hi All, I am a newcomer to using Views and would like to know how to create a date calculations. I'm sure that this is very simple once you know, but I can not find that starting place.
So I want to create a filter on forum topic comments. The first filter gives me only forum topics -- easy enough.
But then I want to only show forum topics which have had comments posted in the past 7 days, so I configure something like this:
field=comment:Last comment time
operator=greater than or equal to
value= ??? DateAdd(Now() - ccyy-mm-07)
option= null
NOTE: I see after the fact that the value field should =now and the option field should =-604800.
Is there documentation anywhere with examples of what functions can be used in these fields?
Most Grateful and sorry for my oversight in the original posting.
Any FAQ's on views for organic group content?
I am looking for help on creating views for content within organic groups. I am looking to do something really simple but after using search for hours cannot seem to find anything on this. Does anyone know where a good FAQ id located on this?
I am looking to simply create a view that will display a list of posts for aq specific content type. Such as: Content type = "story" AND "content posted in current group". In short, I simply want to create views/lists of content types posted within the current OG Group. This can't be that hard but I cannot find anything to help me do this simple task using searches.
Anyone?
Thanks,
Dave
http://groups.drupal.org/node
http://groups.drupal.org/node/1843#comment-11585
filters
@merlinofchaos - huh?
anyway, this request sounds like a View with 2 filters
If this is a page View - you need to use an URL which automatically understands what context it has (sorry, thats kinda vague - but true!). Both of these patterns would do the job:
Thanks Moshe... I have setup
Thanks Moshe...
I have setup my views ok but the big problem I am having (Even after many hours of searching through the forums and the OG support site) is the following...
1... I wish to have the same menu on all groups that have links to the generic views I have created. Example:
"List Stories"
"List Pages"
I cannot figure out how to dynamically create the menu links so it passes the current group NID to the views. Obviously I do not want to create separate menu's for each new group created. I want instead to have the same menu present on each group that simply calls my generic views for listing the individual content types posted within the current view. If I use a generic link to call my view, this makes the user leave the group they were viewing. i.e. all the "Create" menu links for all the content types is gone. I want the user to stay inside the group so when the view is listed the group main menu is still there. Hope that made sense!
So when I talked about a FAQ for this, I have not found any that address this specific issue and was suggesting that this would be a great FAQ to create. (I have seen the same types of questions asked many times but never a good answer to this)
In short, A FAQ for views linking from organic groups would be a great FAQ!
nodeid
You need a custom block for your menu, and your URL will need to be PHP, and in that URL you need to have the node id passed as an argument.
You can search around for ways to capture the node id in your bock and you will find them. Then you pass that URL structure as Moshe said. This is for the block that appears on the group's page, and it will work their. I am sure you can also do this on a page of a node that belongs t a group and then pas the group_nid, in that case.
http://alexrollin.com
Thanks, I have searched
Thanks, I have searched around but cannot seem to find the way to do all this. (I am not a php programmer-can hack a little though) -
I wonder... Perhaps it would be easier to just have my links generated along with the "Create" links that are already being done for the main group menu? Do you happen to know where and how to hack this section of code to include my own links for the views? This might be better as would keep both the "create" and my "list" links together in one menu where they belong anyways.
Thanks,
Dave
http://drupal.org/node/228205
http://drupal.org/node/228205
Here's one for the FAQ:
Here's one for the FAQ: http://drupal.org/node/133063#comment-687988
Another one for the FAQ:
About having two blocks display different sections of the same view:
http://drupal.org/node/209239#comment-689106
How to search multiple fields using one exposed filter
This may not be that common, How to search multiple fields using one exposed filter?
Basiclly needing to generate:
WHERE xyz like 's%' OR abc like 's%'
or even better
xyz like 's%' OR xyz like '% s%' OR abc like 's%' OR abc like '% s%'
It always confuses users where they search for xy and the results returned are like abcdxyfgh.
The particular use case that I need is title like x OR description like x OR [one of 5 cck textfields] like x.
Using OR in filters
I solved a similar problem (I wanted to change the filters/grouping/sort based on arguments) using a custom module and some views hooks. Set up your module and do something like this (not working code, simply ripped the relevant bits from my function):
<?php
function MODULE_views_pre_build(&$view) {
if($view->name == 'your view') { //target only the view you want to mess with
$filters = &$view->display['default']->handler->options['filters']; //grab the filters section of the view object
//at this point you want to get hold of your exposed filter value, not sure how this is handled but arguments were in $view->args
$filters["field_sort_value_A"] = array( //now we add some filters to our view, the best way to get the values you need is to design your filters in the web interface, export the view and examine the array there.
'operator' => 'starts',
'value' => 'A',
'group' => 1, //IMPORTANT: this seems to always be 0 in filters created with the GUI, set it to one here.
'case' => 0,
'id' => 'id',
'table' => 'your_table',
'field' => 'field_to_filter',
'relationship' => 'your_relationship');
$filters["field_sort_value_B"] = array( //and another one
'operator' => 'starts',
'value' => 'B',
'group' => 1,
'case' => 0,
'id' => 'id',
'table' => 'your_table',
'field' => 'field_to_filter',
'relationship' => 'your_relationship');
}
}
//this next function changes the operator for group 1, all the filters in this group will be ORed together, so in this case it will find all the field_to_filter that start with A OR B, any other filters will be ANDed with this. I have not found any way of setting this value in the previous function.
function MODULE_views_query_alter(&$view, &$query) {
if($view->name == 'your view' && $query->where[1]) {
$query->where[1]['type'] = 'OR';
}
}
?>
Multiple relationships for 1 item
The problem I describe here suggests the next q-a:
Q: Can I make a relationship to a non-base table
A: No, you can't, you need a primary key in the referenced table.
Q: If I don't want to make my table a base table (because I don't want it to show up in the Views base table selection when creating a view), how can I make a relationship to that table?
A: Use a join. Take a look at the Advanced help how to do this.
I want to join two tables to my base table. My SQL should look something like this:
"select nid, ... from wishlist
left join node on wishlist.nid=node.nid
left join wishlist_purchased on wishlist.nid=wishlist_purchased.nid
The best thing I could think of is (in wishlist.views.inc, function wishlist_views_data():
// Fields of the table wishlist
$data['wishlist']['nid'] = array(
'title' => t('Wishlist item description node'),
'help' => t('The description of the item.'),
// Because this is a foreign key to the {node} table. This allows us to
// have, when the view is configured with this relationship, all the fields
// for the related node available.
'relationship' => array(
'base' => 'node',
'field' => 'nid',
'handler' => 'views_handler_relationship',
'label' => t('Wishlist node'),
),
);
// To add a relationship with table nid_purchased, we need to duplicate
// the nid field with an alias. Next code should (but doesn't) generate SQL like:
// nid AS nid_purchased
$data['wishlist']['nid_purchased'] = array(
'real field' => 'nid',
'title' => t('Who bought this item and how much'),
'help' => t('Who bought this item and how much did he/she buy.'),
'relationship' => array(
'base' => 'wishlist_purchased',
'field' => 'nid',
'handler' => 'views_handler_relationship',
'label' => t('Wishlist_purchased'),
),
);
But this doesn't work. The result for the join is:
SELECT nid,node_wishlist.nid AS node_wishlist_nid,
title,
wishlist.item_quantity_requested AS wishlist_item_quantity_requested,
wishlist_purch_buyer_uid
FROM drupal_wishlist wishlist
LEFT JOIN drupal_wishlist_purchased wishlist_purchased_wishlist ON wishlist.nid_purchased = wishlist_purchased_wishlist.
LEFT JOIN drupal_node node_wishlist ON wishlist.nid = node_wishlist.nid
It looks like the 'real field' doesn't do anything, and there is no field name after the joined table name 'wishlist_purchased_wishlist'.
How can I join two tables on 1 item?
The biggest problem of the Views module is its documentation. The simplest way to improve very quickly is to put most of it in the docs.php file. I think that is a where everybody will end up.
There is a lot of good information about this module. But that information is very hard to find.
Carl
How do I Views-enable my module?
Just wanted to add that I would really like to see the following webchick-suggested FAQ developed to maturity:
Views for Developers
How do I Views-enable my module?
I'm trying to do this right now after looking at:
I managed to get the default view in the list of views, but when I click on Path or Edit I get a page not found.
If I ever figure this out, I'll post my contribution to this FAQ here.
Arguments View
I have a content type called "performances" that I want to display in a block view on another type "sheets".
The problem is I only want to display the performances that have the same title as the sheets page.
I made a drop down box where users have to choose a referenced sheet title so every performance has a referenced sheet title already.
I just don't know how to set up an argument to display all users who have created a performance for the referenced sheet in a block.
Any help is appreciated!
Wanna alter views, but which is the best way
Hi, I have a module X with predefine views. This views has 1 filter. Now I build module Y and want to alter X's views adding 2 more filters totalling 3 filters for X's views.
I've been searching and find 3 ways to do that.
$x_view = views_get_view('x_view'); $x_view->set_item($display_id, 'filter', 'uid_current', $filter);then save the views.y_views_pre_view(&$view, &$display_id, &$args)and add filters array just like aboveAll solution above produces same result. But If I use way #1, I can see my added filters when I edit the views via Views UI Interface, but not when I use way #2 and #3.
My question is, what should I choose to improve the performance of my module?
I use OpenScholar engine which has Views 2.11
Thanks.
Is this thread still active?
Hello,
I've been learning about views through Johan Falk's unparalleled screencast series "Taming the Beast: Learn Views with NodeOne" and I believe I have a pretty firm grasp of views as a result but I have been having some issues with the less apparent hiccups that seem to be inevitable (but probably have more to do with my in-experience). I have been bothering an author that I bought an e-book from and have been posting videos at youtube: http://www.youtube.com/watch?v=GRmsD5vMCK0&feature=youtu.be but I thought it would be really great to have a dedicated discussion board for such a complicated topic such as configuring views where users can discuss their views configuration problems and solutions to allow newcomers a place to practice/review/work-out views configuration. I noticed this thread belongs to the Views Developers group but I assume this group covers topics on an entirely other level as simple configuration but views is complicated enough to warrant a group for newcomers who just want to gain more experience and resources for configuring views...