Recipe 1: Installing the Views module
Note
Ingredients *
Drupal 5: http://drupal.org
Host login access
Views: http://drupal.org/project/views
Views UI: contained within the Views module
*These ingredients are prerequisite for all of the recipes that follow, and will not be listed in subsequent ingredient lists.
The Views module has a straightforward installation, much like other Drupal module installs. The following recipe instructions incorporate a mix of Windows tools and the command line for locating files, creating directories, downloading files, and unzipping them. Consider following the recipe, but feel free to substitute file management approaches specific to your operating system and preferences. This recipe is followed by a page listing helpful command line shortcuts that you should incorporate into your practice if they are available on your host.
Finding or creating the <DRUPALROOT>/sites/all/modules directory
Log in to your web server. You will need to know your host name, login name, and password.
Locate the Drupal root directory on your server (a common directory location is /
home/your_account/public_html
).If this is the first contributed module in a brand new Drupal installation, you will need to create the
modules
subdirectory.From your Drupal root directory, type the following to change into the
<DRUPALROOT>/sites/all
directory:cd sites/all
Make a new modules directory:
mkdir modules
While you're there, you may as well create the
theme
directory, if it is not there already. We will use this directory in Chapter 7, Techniques for Theming Viewsmkdir themes
Now change to the modules directory:
cd modules
Downloading and uncompressing the module
Open the browser of your choice.
Note
Most of the screenshots in this book use the Firefox browser—a popular choice for many developers. Recipe 8 covers Firefox installation.
Go to http://drupal.org/project/views, and read the page. There are several different versions of Views available for download. We are looking for the Download link marked Recommended for 5.x.
Download the module from the Views project web page. Here is one way to do that:
Right-click in Firefox on Download.
Select Copy Link Location (in Internet Explorer, this link will be called Copy Shortcut). You now have text similar to the following in your clipboard:
http://ftp.drupal.org/files/projects/views-5.x-1.6.tar.gz
A file with the
.tar.gz
extension is affectionately known as a "tarball", reflecting the days when files were backed up onto tape archives.Switch to your Drupal server window. Be sure you are still in your
<DRUPALROOT>/sites/all/modules
directory.Type:
wget <Paste><Enter>
Note
In many shell environments, you can use the right mouse button to paste text from the clipboard. In Windows, you can use Ctrl+V.
The result on your screen, after pasting the download link, will be:
wget http://ftp.drupal.org/files/projects/views-5.x-1.6.tar.gz
After pressing Enter, the download begins. You are provided with a status report of the percent complete as shown in the following screenshot:
Uncompress the module to the
<DRUPALROOT>/sites/all/modules/views
directory. Enter:tar xvf views-5.x-1.5.tar.gz
Depending on your system setup, you may need syntax such as this:
tar -zxvf views-5.x-1.5.tar.gz
You may also use an alternative uncompression tool, such as 7-Zip or WinRAR. WinRAR offers a graphical interface in Windows, but is also available with a command line interface for Mac and Linux systems. The output of the tar xvf views-5.x-1.5.tar.gz command is seen in the following screenshot:
Enabling the module
Return to your browser window. Go to the Module page at:
http://YOURSITE.com/admin/build/modules
.If you are not already logged into your Drupal site as an administrator, you will need to do so. Scroll down to the Views fieldset and enable the Views and the Views UI modules by clicking the two associated checkboxes.
Click on the Save configuration button.
Congratulations! You will now see a message (similar to the screenshot that follows), signaling the successful installation of our module.
Recipe notes
UI is an abbreviation for "User Interface". The Views UI module offers a point-and-click approach for selecting content and output types, controlling view sort order, and so on. The Views UI can even generate a views programming code for you, as we'll see in Chapter 2. If the Views UI module were not enabled, you could still see the existing views and create new views through code. However, the Views UI module is quite helpful: even "Ninja" Drupal programmers will typically enable it.
Command line tips
These shortcuts will assist you in your Drupal development (your host environment may, or may not, have all of these shortcuts enabled).
Press Ctrl+U in the command line to clear everything to the left of the cursor. For instance, if you paste something, and then realize the wrong text was in the clipboard, it may be easier to clear the whole line than to press backspace many times.
Press Ctrl+K on the command line to clear everything to the right of the cursor.
Press the up arrow to re-use a previous command line. You may also search your command history with Ctrl+R.
Type
!$
on the command line to reuse the last argument of the previous command line. For example:more views_ui.module views.module
lets you page through the text of both modules. The last argument of that command was
views.module
. If your next command is:less !$
this will print as:
less views.module
(This tip is difficult to find with a search engine. A Google search for
!$
yields nothing.) Quit both the more and less commands by typing:Q
Use "man" pages. Man is shorthand for the manual.
man less
reveals that
Less is a program similar to more but which allows backward movement in the file as well as forward movement.
Type
cd
to go to your home directory.To return to the previous directory you were in, type:
cd -
If you are not sure where you are in your directory structure, type:
pwd
This is the "print working directory" command, which provides the full path to your current directory. This is especially useful if your prompt is not set up to already display the full path.
Use the Tab key for command line completion. In step 6 of the recipe above, you could type:
tar xvf v<tab>
If there is only one file that begins with
v
in the directory, the Tab key will conveniently complete the full name of the zipped.tar
file:tar xvf views-5.x-1.5.tar.gz
Press Enter to run the command.
If you already had the
votingapi
module installed, for instance, you would need to enter:tar xvf vo<tab>
to distinguish voting from views.