Getting Started with Drupal: A Complete Practical Guide (Part 2)

Original author: Saad Bassi
  • Transfer
Continuation of the first part .

Create a job page using the Views module

Although you can write database queries yourself to read the content, it’s a long and complicated business, even considering the powerful Drupal API .
To build a page with a list of vacancies, we use Views  - a module that allows you to retrieve content from a database without writing code at all.
Simply put, Views is the user interface for building MySQL queries. Views is an incredibly powerful module, but sometimes it can be difficult for beginners to master. The best way to deal with Views is to play a little with it, which we will do now.

Install Views

First of all, we need to install Views. After downloading , installing and turning on the module, it will be available in the section "Site Design". When installing, do not forget to unzip its translation into the folder with the module.
Create the first view

Any dataset output by the Views module is called a view .
We will create a view that displays a list of available vacancies on the page. Also with the help of Views you can make attachments, blocks and custom RSS-feeds, but for now we will analyze something simpler.
Go to the menu on the page Site Design> Views> Add and fill in the fields as shown in the image:
Create a view
Then Drupal displays the user interface for creating views. Do not worry, we will discuss it soon.
What is a view?

To start creating a view, we need to understand what a view is. Views display our data in various styles. There can be several types in one view.
To represent the vacancies, we will create 2 types: page and block. We will return to this topic a bit later.
Adding fields to the view

Let's add some fields to our view. Fields are the content that we want to display on the page. Click the plus sign (+) in the Fields area to add fields to the view.
Add fields
We will display the title, creation date, department, salary and experience specified by the user in the form of posting vacancies.
We need to select these fields from the additional list that appears after clicking the plus button (+). We are interested in the following fields:
  • Material: Header
  • Material: Creation Date
  • Content: Department
  • Content: Salary
  • Content: Experience

Add fields
After selecting the required fields, click the "Add" button to proceed to setting up each field individually.
After clicking the “Add” button, the section for setting the Content: Department field will appear first . Leave it as it is, with the exception of the "Format" selector, setting it to "Simple Text"; then click Refresh.
Setting the Content: Department field
Now configure the Content: Experience field . Do not change anything, just click "Update." And do the same with the Salary field .
When done with the content fields, you will need to configure the Material: Creation Date field . Just change the Date Format fieldto the value “Time back”, so that the field displays how much time has passed since the vacancy was published (for example, “12 days ago”).
Customize Material: Creation Date
The next and final field for customization is Material: Title . We just need to put a checkmark indicating that the title should be a link to the vacancy page.
Field Setting Material: Title

You can use the preview tab to see the result of your settings:
basic settings

Now let’s set the basic presentation settings.
basic settings
We will choose theNo formattingstyle , and the data will be displayed in a tabular format. When you make these settings, click Refresh.
basic settings
We would like to display all vacancies without splitting into several pages, so the option “Page by page” - say solid “ No ”. And again, click "Update."
basic settings
As you can see, after all these manipulations, our view looks better than before. But we are not done yet.
The view already looks better
View Filters

Currently, the view displays all the contents of the site, including non-vacancies. And we want to display only vacancies.
To do this, select two filters that specify the output of only published vacancies:
  • Material: Published
  • Material: Type

Click the plus sign (+) in the Filters area, then select Material: Published and Material: Type ; Click Add.
View Filters
Set the filter Material: Published : specify the value “Yes”, this will exclude unpublished materials from our submission.
Set the “Material: Type” filter so that only materials of the “Vacancy” type fall into the view.
Jobs only
Take a look at the result of the filters in the preview:
Sorting criteria

From the preview it is clear that the vacancies are sorted by date from old to new. It would be great to bring out new vacancies first.
To display new vacancies first, we will apply the sorting criterion. In the list of fields for sorting, which will appear after clicking on the plus in the corresponding area, select Material: Creation date .
Sorting criteria
Specify the sort order Descending .
The sort order
Refresh the preview again; Now the latest vacancies will be displayed first.
Reorder fields

There is one more thing to improve our understanding: changing the order of the fields. It makes sense to display the header field first, the date field second, etc. You can change the order by clicking on the button with the "up / down" icon in the "Fields" section.
Reorder fields
Update the preview: the view is even better.
We are done with creating a presentation; Now we add two types to it.
Add a page view

On the left side of the views page, select “ Page ” and click “ Add View ”. You will automatically be redirected to the "Page Settings" section.
Add a page view
We need to specify the path to the page and choose a place to link to it. I specified a weight of 2 to display it after the "Home" link.
Page Menu Settings
After entering the values, do not forget to click “Save”.
Now you can see how the link (called "Available Jobs") to the page with our view looks in the main navigation.
Available jobs
Create a block view

Blocks are used to display information in various regions of the site. These are widgets that display data such as current events, the five most popular articles, and so on. Blocks are displayed in regions such as the left sidebar, title, footer, and others.
You can place blocks in the header, basement, and left and right panels in the standard Drupal theme. Blocks are managed from the Administration> Site Design> Blocks menu .
Block management
Now create another view to represent the “Jobs”; view showing the latest job advertisements in the right pane.
Go to Administration> Site Design> Views and click on the link to editperformance of "Jobs". On the left, select "Block" and click "Add View", as before.
Override Button

We will remove 3 fields from the block view so that the block fits in the sidebar and is not overloaded with information. To do this, click on each field in the "Fields" section. Before deleting the field, be sure to click the Override button , otherwise you will change the basic view and at the same time the page view, which we did a little earlier.
Delete fields
You can also change the name of the block that will be displayed on the administration page.
Change the name of the block
Add a block to the sidebar

Let's move on to block management and add our new block view to the right panel.
Go to Administration> Site Design and click on Blocks .
In the “ Disabled ” section , find the newly created block and select the right column in the “ Region ” column .
Do not forget to click “Save” to confirm the changes.
And here is the block
Excellent! This completes the development of the job board.
Drupal Themes

To conclude the tutorial, let's discuss the themes. Themes are used to change the appearance of the site.
On the Internet you can find a great many topics. Here, for example, is a list of topics posted on the official website of Drupal.
To install a new theme, you need to download and unzip it into a directory drupal/sites/all/themes
. If this directory does not exist, create it.
To turn themes on and off, go to Administration> Site Design> Themes .
There are 5 topics in the Drupal distribution. For example, I activated the Marvin theme to give our new site a fresh, new look:
Fresh, new look
Do not forget to mark the desired theme as the default one so that it is used on the site.
To summarize

I tried my best, trying to cover the most complex and incomprehensible aspects for beginners. One way or another, this guide is just one of the reflections of Drupal's true power. I recommend that you research on your own for more complex topics.
If you have any questions, feel free to ask them in the comments. I will be happy to help you.
Useful sites

  •  is a Russian-speaking community of Drupal users.
  • API Reference  - API reference for programmers.
  •  is a community of translators of Drupal and its modules into Russian, Belarusian, Kazakh and other languages.
  • Dancing Near Drupal  - Articles, lessons, and tips authored by the famous Drupal developer, neochief .
  •  - recipes for creating sites on Drupal; A huge collection of tips and tricks.
  •  - tips, tricks and forum; the site has Drupal Planet, an RSS feed that collects news from sites and blogs dedicated to Drupal.

Discussion on

UPD 01: Habrauser kost revealed an incorrect picture.

Also popular now: