So you know how to use Views, but feel like you're just scratching the surface. Views is a powerful module that allows you to build out complex functionality with just a few clicks of the mouse. This session will cover some of the more advanced features of the Views and take your knowledge of Views to the next level.
Topics include:
Changing the Results (adding more data, filtering options)
Contextual Filters (Arguments)
Relationships: Pulling in Related Data to Views
Formatting Views and Changing the Markup
Creating Administrative and Interactive Views
Extending Views with Other Modules
2. About me
• Drupal consulting,
development, and
training
• Help organizations build
@suzanne_kennedy awesome Drupal
evolvingweb.ca websites with custom
functionality
3. What Can You Do with
Views?
• Site Building Tools
• Lists of content
• A way to build pages and blocks
• Related content blocks
• Interactive Lists
• Fancy lists (calendars, slideshows, maps)
• User control of sorts/filters
9. Choose What to List
Content Users Taxonomy Comments
Content title D. Schrute
adventure Wow, can't
Germany city breakwait to get
dwight
city break 8 Sept visit.
J. Halpert
Spain sailing
joe Me too!
shopping 8 Sept
11. Choose a Display
Web Page Title
http://example.com/city-guides Google
Page
display
(banner)
City guides Sign up
Beppu name
Far far away, behind the word mountains, far from the countries Vokalia and
Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at
the coast of the Semantics, a large language ocean.
email
Block
display
Button
Paris
Far far away, behind the word mountains, far from the countries Vokalia and
Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at
City guides by topic
the coast of the Semantics, a large language ocean. Budget
City break
Mali Family
Far far away, behind the word mountains, far from the countries Vokalia and
Luxury
Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at Sun and sea
the coast of the Semantics, a large language ocean.
19. What are Contextual
Filters?
• Dynamic filters
• Filter content based on the context of the view
• Aka arguments
Eddie
Eddie likes to travel with his mandolin. Or sometimes the
ukelele. In a pinch, he'll travel with just his tambourine.
By this contributor...
Best in Beppu
Far far away, behind the word mountains, far from the countries Vokalia and
Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at
the coast of the Semantics, a large language ocean.
Paris excursions
Far far away, behind the word mountains, far from the countries Vokalia and
20. Where does the context
come from?
• The URL
• node/24
• taxonomy/term/
• Passed directly to the view
• From Panels
• In code
• PHP Code
• Add custom code snippet to determine
what argument to pass to the view (Bad)
22. Examples
• Author Page: Show content by this author
• Blog Post: Show blog posts in the same
category
• Any Node Page: Show fields from the
current node
28. Add Relationship to an
Instructor Node
Course Instructor
Course Title Name
Department Field Specialty Field
Course No. Field Entity Reference
Instructor Field
31. Inverse Relationships with
Entity Reference
• Course->Instructor: Create a relationship
from your result to the referenced content
• Instructor->Course Create an inverse
relationship from the referenced content to
the referencing content
32. Other Use Cases
• Blog posts: Info about the author of a node
• Admin view of nodes: Link to translations
• Events calendar: Info about room location
33. Relationships + Contextual
Filters Examples
• Blog Post: Show the other blog posts by the
post’s author
• Course Page: Show other courses by the
course’s instructor
40. Your Custom Data
• hook_views_data
• Tell Views about the custom data that you’ve
added with your module
• http://evolvingweb.ca/story/developing-
views-part-i-describing-your-data-views
65. Theme preprocess
functions for Views
mytheme_preprocess_views_view(&$vars) - generic for all views
mytheme_process_views_view(&$vars) - generic for all views
mytheme_preprocess_views_view_list(&$vars) - generic for List style views
mytheme_preprocess_views_view_field(&$vars) - generic for each field
69. Modules for Filtering
• Better Exposed Filters
• Provides more options for exposed filters
• Views Dependent Filters
• Exposed filters that show up when a
particular option is selected
Get people to open their manuals, and check out the “before you start” activity. This is an activity for people who arrive early. It is optional. Whether they are familiar with this technique or not, it is useful. Wireframes can make it easier for participants to communicate their questions. Go around and try to get familiar with the kinds of projects students are interested in, find some commons threads you can bring up later. \n
Fill in information about your company!! Or ALT+TAB to your own site, or add in your own slides.\n
With these things, you can create\n
First frame the problem that Views was made to conquer. \n
This is an example of custom PHP development - combining queries, logic and display. You’d connect to your database, gather data, and then display it- in this case the HTML output is a table. Later if you wanted to change the query or change the output, you’d have to edit code like this.\n
Each time you make a new View you start with the wizard. Note: when you select Show content/users/taxonomy- that is the base table and you can’t change that later.\n
You can get most things done right from within the wizard. Note that the WIZARD disappears after your initial set up.\n
And when you want to access the advanced settings, there is the full UI. \n1. You can change for example, if content is listed in a TABLE or in a bulleted list. \n2. You can add filters, and change the default sort orders. \n3. You can specific what path it’s on and who can access it. \n4. You can relate content to other content by checking the context. \n
First you select the kind of information you want to query. Views can query Content, users, taxonomy and comments. This cannot be changed afterwards. Say for example, you want to query content. \n
You can then pull individual fields to display, instead of showing the whole record. Views can then be output in a number of formats. As an HTML list, or just showing two specific fields, as a sortable table, or as points on a map, using a mapping module to extend Views.\n
Content can be output in various ways. For example, as a page with a full path. Or as a block that can be placed in the layout. Or as an RSS feed, attachment, etc. We’ll see how to do this soon!\n
\n
\n
\n
\n
\n
\n
You can WAIT to do this part of the presentation until after you have demo’d the basic functionality. \n
This shows a list of author content showing on the user’s profile page.\nOther examples could be “show me a list of MY content in a block on the site”\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
You can WAIT to do this part of the presentation until after you have demo’d the basic functionality. \n
1st - select the region field. formatted as plain text. \n2nd - rewrite the output so the two fields are in one row.\n3rd, this shows the out roughly. \n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
At the bottom of the Views UI you see the query code output.\n
At the bottom of the Views UI you see the query code output.\n
Good things to know about Views!\n
Apply what you’ve learned to new situations.\nContinue to keep track of developments in the community.\nImprove your site building skills by becoming familiar with more popular modules.\nLook at popular Drupal websites to learn: How did they do that?\n