Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

What are the relationships and arguments in Views? How do I use them? I have read some tutorials, but still don't know how to use them. Can someone explain them more clearly? Thank you.

share|improve this question
add comment

2 Answers

up vote 8 down vote accepted

Relationships are the way Views expresses SQL joins. For example, when viewing a node, you can add a relationship to it's author, pulling in even more data.

Arguments have been renamed "Contextual Filters" in Views 7.x-3.x, which is a better name. Basically, it's a filter that gets its input from the the page, either by the page's URL or the node or user being viewed, etc.

share|improve this answer
add comment

Arguments (or, as mentioned, Contextual Filters) are an incredibly powerful tool in making views context aware. Aside from using the current node, taxonomy term, path, etc. to filter your data, you can use Views arguments in conjunction with the Panels module to create really complex page layouts. The degree to which you can do this with just Views varies based on what you want, though.

Let's say you want a user who goes to /category/books/ to see all nodes or content type 'book', but when he opens /category/malbum/, he should see all nodes of content type 'album' (or tagged with taxonomy term 'album', for example). Without Contextual Filters, you'd have to create two separate views. But if you add the path, taxonomy term, or whatever else you use to mark a node as 'book' as an argument, you can create a single view that does all this AND that accomodate future categories.

With relationships it gets even better. Every book/album has an 'author'. If you want to add, say, the age of the author to the view, you can't do this without relationships, as 'age' is part of an author node, not the book node. In this case you create a relationship, and then you can add the 'age' field from the author content type, as if it was a field in your book node.

The specifics of how to do these things are explained in a number articles and videos, but conceptually I hope this will help you understand it a bit better.

share|improve this answer
    
Could you post just 1 article or video which does this right? –  cherouvim Apr 2 '12 at 10:22
    
drupaleasy.com/blogs/ultimike/2009/07/… This article relates to these tricky things –  ted.strauss Jul 9 '12 at 15:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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