• Save
How to Use the Views UI and Theme a View
Upcoming SlideShare
Loading in...5

How to Use the Views UI and Theme a View



Views is a popular Drupal contrib module that speeds up development time for many types of websites. Essentially it enables you to grab almost any piece of information available on your site and ...

Views is a popular Drupal contrib module that speeds up development time for many types of websites. Essentially it enables you to grab almost any piece of information available on your site and present it in many different ways, as lists of content, without having to write any (or much) code.

This session will introduce how to build a "view" using the Views UI. The second half will cover Views theming.



Total Views
Views on SlideShare
Embed Views



5 Embeds 137

http://www.chapterthree.com 73
http://www.slideshare.net 47
http://chapterthree.com 7
http://dev-c3d7.chapterthree.com 7
http://dev.c3.gotpantheon.com 3



Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

How to Use the Views UI and Theme a View How to Use the Views UI and Theme a View Presentation Transcript

  • How to Use the Views UI and Theme a “View” Presented by Squiggy Rubio Oct. 17 th 2009
  • Drupal is used a lot as a content management system Lets see what it offers out of the box...
  • Finding and managing content is hidden in the Administer menu It has one filter to sort through all nodes This may be fine for smaller sites, but what about sites with thousands of nodes?
  • What is needed is a dashbord to control and present content
  • Source: http://www.funny-potato.com/cockpits-pictures.html
  • Just kidding!
  • What you need is Views
  • What is Views?
    • Creates custom lists of content
    • Provides many options for what content to display and how to present it
      • Lets you do all this without writing any (or very much) code
      • As of Views 2, almost any piece of information in your Drupal site can be accessed by the Views module
    • Views is a contrib module created and maintained by Earl Miles
  • Who is Views for? Anyone who wants to speed up creating a site that requires special lists of content, not already available in Drupal core Anyone who is familiar with setting up and configuring a Drupal site and extending it with contributed modules
  • Structure of a “view” Source: Found in the documentation of the Advanced Help module ( http://drupal.org/project/advanced_help )
  • View “Style” You can wrap your rows in a table, grid, list, or unformatted divs
  • Row styles can be nodes or fields
  • Row style: Nodes
    • Can display the full node or the teaser
    • Markup is handled in node templates
    • Doesn't require theming views fields (phew!)
  • Row style: Fields Title: Some interesting title Date: October 18, 2009 Type: Photo Title: Another interesting title Date: October 18, 2009 Type: Video
  • Options that affect theming
    • Basic settings
      • Style: selects markup to wrap rows in, such as 'unformatted', table, HTML List, or Grid
      • Row style: selects either nodes or fields
      • Pager
      • Items to display
      • Header and/or footer input
      • More link
    • Fields (not available if row style is set to nodes)
  • Setup one view, then create many variations with “displays”
    • Display types:
    • Page : gives the display a path so that the view is a self contained page
    • Pane : lets you embed your view in a Panel page (requires the Panels module)
    • Block : lets you embed your view into any block region or Panels layout
    • Attachment
    • Feed
  • Theming a “View”
    • Views markup and classes accounts for most theming needs
    • If you want to change the markup in a view, Views provides a handy theming wizard in the Views UI
    • Provides a list of template suggestions.
    • Available template names will apply theming to various levels of your view, from broad to more specific.
    • For example, you can select views-view—list.php and that will let you define the markup for all views that wrap their rows in a list. Or select views-view-list--media-listings--block-1.tpl.php and that will apply to just the current block display.
  • Default templates in Views views-view.tpl.php views-view-unformatted.tpl.php views-view-list.tpl.php views-view-fields.tpl.php views-view-field.tpl.php Note: the Advanced Help module has excellent documentation with what each of these templates applies to. I will focus on the views-view-fields.tpl.php.
  • Inside views-view-fields.tpl.php Contains a lot of logic, like foreach loops, etc) This is confusing if one doesn't know a lot of PHP
  • This logic provides a general way to formate fields generated from the Views UI. However, it's not always needed for every view. If you're certain the fields you're view uses will not change frequently (or you don't mind updating your template file), you can replace this logic and default markup with your own markup. Then pull the individual fields into your markup.
  • Syntax for views-view-fields.tpl.php Fields are the most common views element that need to be themed. The fields are stored in $fields, which is an array of field objects. Use this syntax to pull the fields out of the array to arrange them in your custom markup: <?php print $fields['title']->content; ?> The 'title' above is the name of your field. You can find the field names the Views UI.
  • Some excellent Views resources Views project page http://drupal.org/project/views Advanced Help module (has excellent documentation, including a very good section on Views theming) http://drupal.org/project/advanced_help Views 2 theming (on drupal.org) http://drupal.org/node/352970 Views Developers (on groups.drupal.org) http://groups.drupal.org/views-developers