This article is intended for non-technical users of Drupal. If you are a PHP developer who needs a primer on what Views are, then you might want to check out my “Drupal Views for Developers” article for an Overview look at views from that perspective.
Regardless of your background in PHP development, if you’ve played around with the Drupal CMS system at any length, you’ve undoubtedly run into this crazy piece of functionality called “Views”.
Usually end-users hit this when there is an element on their webpage they want to change but when they click on the little “gear” icon to modify the block, they discover that there is no content in the block to change. It appears to be empty in the administrator screen, but when viewed on the live site there is data in the block. Where does it come from?
Upon further investigation, they discover that there is a mysterious thing called a “View” that is magically populating the block, and the investigation usually ends there because no matter what they do, they can’t “see” the stuff they want to change.
Is that what happened to you?
Part of the problem is that the good folks who developed Drupal came up with a misleading name for this piece of functionality; the word “Views” doesn’t really reflect what is going on under the hood at all. The rest of the problem is that Drupal relies heavily on Views to operate, and it is nearly impossible to understand them without having at least a conceptual understanding of what PHP, SQL, and CSS programming are.
So, that’s what this article is about: providing the high-level overview understanding of what Views is, and how it fits in with PHP, SQL and CSS. I’ll also take a stab at explaining why Views is a good thing even if it isn’t easy for non-technical Drupal Admins to get their heads around, and finally I’ll give you some links to some resources to help you take the next step towards understanding how you can make this powerful tool work for you.
First, let’s get some definitions out of the way
- SQL – it’s pronounced “Sequel” and this is your database. This is where all the information in your website is stored: all your page content, blog posts, articles, descriptions and menu items.
- PHP – this is the programming language that your Drupal site is programmed in. It provides all the mechanical and moving parts that make your website work. It takes the information from your database and creates HTML and DIV structure that gets sent to the end-user’s browser.
- CSS - the formatting part of the process. It determines how the content looks when viewed in a browser. It describes the placement of the elements on the page, what those elements look like, and how they behave when a user interacts with them.
Drupal Views Are Really Lists
Now that you have a basic understanding of the programming languages involved the next thing you should understand is that a much better name for Views would have been “Formatted Lists”, because that’s essentially what they are.
The View contains a series of conditions which query the database (that’s the SQL part of the process) for lists of information. When the results of the query are returned from the database the View contains instructions for sorting and rewriting field results and creating the HTML code that gets returned to the browser (that is the PHP portion of this endeavor). Finally, the View adds wrapper tags with classes to format the data according to the stylistic definitions that have been supplied by the designer (and this is the CSS portion).
An Example is Helpful Here
The most common example is a list of blog posts. You might have written over 100 blog posts on your blog, but you only want to display the last three on your homepage.
- The Query (SQL) Part: Views allows you to quickly create a block element that pulls only the last three blog posts. Whenever a new post is added, the View automagically updates the homepage to display the latest three blog posts.
- The PHP (Programming) Part: So, you have the list, but now it needs a bit more work. Perhaps you want to display a snippet of the first 400 characters of the blog post underneath the posts’ titles as a teaser. You can set parameters in the Field list to trim the teaser snippet down to the required length (in this case you would modify the “Rewrite Results” section within the View).
- The CSS (Styling) Part: You can assign CSS classes to wrapper divs around the fields returned by your View so that you can format the content in the list to look good in your layout.
The beauty of all of this is that you don’t need to understand the PHP, SQL or even CSS coding in order to manage Views. Just like driving a car, you don’t need to know how the engine works in order to understand its function.
Ok, so what does all this mean to the average Drupal Admin who doesn’t know PHP?
The short story is that you don’t want to play around with Views on your live site. There are just too many ways to hose your website and unless you have someone competent sitting next to you who can help you fix it, it could be a job killer. Even experienced developers typically make a backup copy of the website to develop on and then copy the completed revisions up to the live site once they have been approved.
So, the first step is to set up a development environment or sandbox account to play with. My recommendation is to install a basic Drupal site on a laptop that won’t have a negative effect on any production servers. This is the best way to keep the IT guys off your back long enough to learn the tool, while also giving you maximum flexibility to install, hose, and reinstall Drupal as needed without ill-effects.
Once you’ve done that, take a look at this set of videos that was produced by a Scandinavian Drupal trainer who works for a Drupal development company called NodeOne. It’s a long story, but essentially his flight got cancelled in Chicago and he was stuck in a hotel room drinking Swiss Miss and had nothing better to do than make about 10 hours-worth of screen casts explaining more than you would ever care to know about Drupal Views (even if you aren’t a developer). You can view the tutorials here and I’ll let him explain the whole hot chocolate thing.
Also, keep in mind that you don’t need to watch all 27 screencasts. In my opinion most of the useful information is contained in the first 8 or 10 screencasts.
The bottom line is this: If you are a Drupal Admin who has been tasked with modifying the way a list of blog articles is appearing on the homepage of your corporate website, then it may be a good idea to take a step back and learn the fundamentals first. This is not something you can tackle in 20 minutes if you don’t already know the tool.
Views is a difficult subject to get into whether you have a programming background or not. However, from my perspective much of the difficulty stems from non-intuitive terminology. The functionality is, fortunately much more intuitive than the terminology. Taking the time to work through learning what the tool does is a matter of watching a few videos and learning how to ask the right questions in the search engines.
In the end, if you stick with it then you’ll feel more competent the next time you’re facing what appears to be an empty block in the content administrator that seems to magically have content when it’s run on the live site. And once you know Views, you’ll know a great deal about Drupal because so much of what Drupal does relies on an understanding of Views.