Drupal Features News
In this lesson, I’ll show you how to reuse site functionality by copying it using a Feature module. Let’s start with something simple—creating a news feed that includes:
- A "News" menu link to the news page
- A news page
- A news block for the front page
This should be enough to understand how the Features module works.
First, install the required modules:
Create a content type called “News” and add a few nodes of that type.
Now let’s create a View with both a page and a block display.
Page:
- Title: News
- Format: Unformatted list
- Show: Content | Teaser
- Filter criteria: Published = Yes, Type = News
- Sort criteria: Post date (desc)
- Page settings: Path = /news, Menu = Normal menu entry: News
- Access: Permissions | View published content
- Pager: Full pager, 10 items per page
Block:
- Title: News
- Format: Unformatted list
- Show: Fields
- Fields: Title
- Filter criteria: Published = Yes, Type = News
- Sort criteria: Post date (desc)
- Pager: Display a specified number of items | 5 items
Assign the block to a region in the admin UI. At /news
, you should now see something like this:
You can improve this view later by adding a date or teaser field. For now, it’s intentionally simple so we can later demonstrate how to update a Feature module.
Create the Feature module:
Click Create new feature and fill out the form:
- Name: drupalbook.org News feature
- Description: Provides a news page and block
- Version: 7.x-1.0-alpha1
Important: Use a unique name (not just "news" or "blog") to avoid conflicts.
Select the View you created (“News”)—it will include both the page and block. Also, add the content type “News”.
Once selected, click Download feature to get the module archive. You can install it like any other module.
Installing on another site:
Install the Features module and your downloaded feature on the new site:
Now you can start creating news items on the new site. Don’t forget to place the news block in the sidebar.
Note: Only functionality is transferred—not the content (nodes). To transfer content to another site, use the Feeds module. I’ll cover it in a future lesson in my Drupal guide.