Tips and Tricks for Getting the Most out of Views

Preview:

DESCRIPTION

 

Citation preview

Tips and Tricks for Getting the Most out of Views

About me

• Drupal consulting, development, and training

• Help organizations build awesome Drupal websites with custom functionality

@suzanne_kennedy

evolvingweb.ca

Introduction to Views

What is Views?

Fields

Sorts

Filters

View

Taxonomy

city break

CommentsUsers

D. SchruteGermany

J. HalpertSpain

adventure

city break

sailing

shopping

dwight8 Sept

Wow, can't wait to get visit.

joe8 Sept

Me too!

Content

Content title

Data

Views BasicsTaxonomy

city break

CommentsUsers

D. SchruteGermany

J. HalpertSpain

adventure

city break

sailing

shopping

dwight8 Sept

Wow, can't wait to get visit.

joe8 Sept

Me too!

Content

Content title

Choose what to list

Choose a format

Choose a display type

Unformatted List Table

Add filters and sorts

Website Header Block Display

Page Display

Choose What to List

Taxonomy

city break

CommentsUsers

D. SchruteGermany

J. HalpertSpain

adventure

city break

sailing

shopping

dwight8 Sept

Wow, can't wait to get visit.

joe8 Sept

Me too!

Content

Content title

Add Filters & Sorts

Sort by title

Sort by post date

Filter by content typeArticles Job Postings

Jan 10

March 16

April 6

April 28

Ascending Descending

Jan 10

March 16

April 6

April 28

Ascending

A

Z

Z

A

Descending

Choose a FormatUnformatted HTML List Ordered List

Table

Ordered List

Calendar Map

Choose a Display

Website Header Block Display

Page Display

RSS Feed Display

Attachment Display

Anatomy of a View

ArticlesWelcome to the articles page.

Title

Header

Row

First | Prev | 1 | 2 | 3 | Next | Last Pager

Results

Anatomy of a View

ArticlesWelcome to the articles page.

Title

Header

Row

First | Prev | 1 | 2 | 3 | Next | Last Pager

Results

Views: Query builder• <?php

// Connecting, selecting database$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password') or die('Could not connect: ' . mysql_error());echo 'Connected successfully';mysql_select_db('my_database') or die('Could not select database');

// Performing SQL query$query = 'SELECT * FROM my_table';$result = mysql_query($query) or die('Query failed: ' . mysql_error());

// Printing results in HTMLecho "<table>\n";while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "\t<tr>\n"; foreach ($line as $col_value) { echo "\t\t<td>$col_value</td>\n"; } echo "\t</tr>\n";}echo "</table>\n";

// Free resultsetmysql_free_result($result);

// Closing connectionmysql_close($link);?>

• // Printing results in HTMLecho "<table>\n";while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "\t<tr>\n"; foreach ($line as $col_value) { echo "\t\t<td>$col_value</td>\n"; } echo "\t</tr>\n";}echo "</table>\n";

Views Wizard

Choose base tableChange typesTerm filtersSimple sort

Views Wizard

Page or blockDisplay settingsAdd to menu

Views Editor

CHANGING THE MARKUP

Choose a FormatUnformatted HTML List Ordered List

Table

Ordered List

Calendar Map

Choose the right format

Built-in Formats• Table• Unformatted List• HTML List• Jump List• Grid

Use grids for visual data

Use tables for tabular data

Display ‘Fields’ for more Control

Change the row style

Row style setting

Row Styles

Fields ContentSelect the exact fields that

you want to displaySelect the view mode to use

Select a row style (content or fields)

Change the markup for fields in configuration

Altering Field Output

Exclude fields and rewrite results

Altering Field Output

Altering Field Output

Use Field Formatters

http://blog.brightcove.com

Use custom view modes

Define custom View modes with Display Suite

Add multiple displays to the same View

Multiple Displays

Add displaysAdd displays

Override Settings

Select to change settings for the current display or all displays

Use attachments to make a ‘featured item’

Group results for easy scanning

Select grouping field

Use Views to Create RSS Feeds

Attach a Feed Display

Link a block to a page display

Link a block to a page

Link display setting

FILTERING AND SORTING

Add Filters & Sorts

Sort by title

Sort by post date

Filter by content typeArticles Job Postings

Jan 10

March 16

April 6

April 28

Ascending Descending

Jan 10

March 16

April 6

April 28

Ascending

A

Z

Z

A

Descending

Adding FiltersAdd something to filter by

Configure it

Filter by whether a field exists

Operators for Filters

Filter to show onlyusers who have a picture.

Use exposed filters to let users filter content

Exposing a filter

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

Use exposed filters for search

Exposing Search• Provide a ‘keywords’ exposed filter

Exposing Search

Display content in a table and expose sorts

Exposed Sorts• Use a table view and expose sorts to users

Exposed Sorts

Use the Date Views module

Upcoming Events View

Filtering by Date

Filter to only show results with a start date in the future

USING CONTEXTUAL FILTERS AND RELATIONSHIPS

Contextual Filters: Page

Website Header

Page Display

Alias: category/tags/drupal

Drupal System Path: taxonomy/term/1Content About ‘Drupal’Views Configuration: taxonomy/term/%

URL: evolvingweb.ca/category/tags/drupal

Contextual Filters: Page

Add a contextual filter

Configure it

Contextual Filters: Block

Website HeaderBlock Display

Alias: content/blog-post-title

Drupal System Path: node/1

URL: evolvingweb.ca/content/blog-post-title

Node 1 Content

Tags for Node 1

Contextual Filters: Block

Add a contextual filter

Configure it

Use contextual filters to show related content

Field in Separate Block

View showing the technology field. Uses contextual filter to show only data for current node.

Related Media Block

View showing the ‘Related Videos’ field. Uses contextual filter to show only data for current node.

Use contextual filters to exclude results

Exclude current node

Exclude arguments

EXTENDING VIEWS

Setup Views for administrators

Administrative Views

Draggable Views

Draggable Views

Views Bulk Operations

Use Views & Apache Solr

Apache Solr• Apache Solr Views Integration module

Display more data with Views

What else can you show with Views?

• Aggregator items• Solr search results• Content Revisions• Products• Media• Webform Submissions• Files

Your Custom Data

Use Views Slideshow for dynamic rotators

Views Slideshow

Views Slideshow Config

Use the Calendar Module

Calendar

https://buyandsell.gc.ca/event-calendar

https://ed.stanford.edu/events

Building a Calendar• Calendar provides a views template

Maps!

Open Layers Views

http://www.gfptt.org/

WORKING WITH VIEWS

Preview Output

Previewing Output

Export Your Views

Views in CodeExport Views

Add Views to Your Features

Use the ‘Theme Information’ link

Theme Information

Theme Information

Recommended