The following tutorial is a suggestion. It is not the only way to display news in your website, but it is a way to do it using the components provided by the infrastructure.
Pre-requisites
In order to follow the tutorial below, you should first enable 2 Drupal modules: CERN Components and CERN Display Formats. The modules are already installed in the infrastructure (hence to your website) so just navigate to Extend from the admin bar, search for the modules and enable them.
1) Create a Content Type
First of all you need a content type that constitutes the News Content Type.
- Navigate to Structure > Content Types > New Content Type
- Give a name to the content type (eg. News)
- Add some meaningful fields
- Body: Text Field
- Image: Image Field
- Publication Date: Date Field
- Tags: Reference to taxonomy
2) Setup how the News node will be displayed
In this step you setup how the node will look like when you visit it. This is done by setting up the Full Content display of the content type you created in step 1.
- Visit the Manage Display settings of the content type you created in step 1.
- Enable the Full Content view mode of the content type and click Save.
- Visit the Full Content tab and choose a layout for your News pages. Our suggestion is to use the News Full Content pattern. Select this pattern and map the fields to the ones of the pattern.
- Save the display.
3) Setup a view page to display and filter all your news
Having setup how each news node will look like when you visit it, it is good to have a page where the site visitors can search for the news you will publish. In Drupal terms, this job is done by a view and the final result will look something like the following image (without the colours). To explain the process in a better, this step will be broken into 2 sub-steps.
(a) Setup how each news piece will be rendered in the view
In this step you will setup how each one of the news pieces will be rendered (marked red in the image above)
- Visit the Manage Display of the News content you have already created (Structure > Content Types > News > Manage Display)
- In the tabs list on the top of the page, select a display to map (eg. Teaser)
- At the bottom of the display select to render this display using the Preview List display.Map the fields of the news content type to the ones of the pattern as shown in the documentation of Preview list.
- Save the display
(b) Setup the view
Having setup how each node will be displayed in the previous step, its time to setup the view that will gather all news in one page and add search fields. This is done by creating a view.
- Create a view by navigating in Structure > Views > Add View
- Fill the initial data of the view
- Give a name to the view (eg. "News" or "All News")
- Show Content of type News
- Create a page with a title and a URL
- Save
- In the view settings:
- Select Teaser List as Format
- Show Display Suite: Content and select as view mode the display you mapped in step (a). In our case it was Teaser.
- Under Filter Criteria add the fields that you want to expose to the visitors of your page. Eg. Title, publication date etc. In order to expose a filter, you should check the option "Expose this filter to visitors, to allow them to change it" as in the picture below.
- Add any other configuration you think is useful. For example sorting criteria, number of results shown in the view etc.
- Save the view
4) (Optional) Setup a URL alias pattern
A nice to your content type is to have a common alias pattern for all the news pages. For example you might want your news to have a URL of type /news/<title-of-your-news-piece>. In order to achieve this:
- Navigate to the URL alias settings (Configuration > URL aliases > Patterns > Add Pathauto Pattern
- Select Pattern type Content and Content Type the News one.
- In Path Pattern, you should fill the pattern that your nodes will have
- For constant words (eg. /news/) use words
- For dynamic values (eg. <title-of-your-news-piece>) you should use tokens. To find the available tokens, click on Browse Available Tokens
- Eg. in order to have the pattern /news/<title-of-your-news-piece>, the pattern value should be "/news/[node:title]"
- Save the settings.
After setting up the alias pattern, every News node created after this moment will get the URL alias you have set