Views has long been one of the magic pieces that makes Drupal my CMS of choice. Views allows us to easily create queries of content in the UI, giving great power to the site builder.
>> Dự án implemented Phalcon với Drupal, Drupal 9 sẽ có
>> Giới thiệu the future of decoupled Drupal
>> Hướng dẫn Integrating multisite Drupal với Apache Solr
When you first create a view, the default, obvious choice is to create a "Page" display of the view. A Page has a URL that people can visit to see the information, and gets us as site builders closer to job done. However, I don't want you to do it!
When you first create a view, the options are that you can make a Page and a Block. Selecting neither will allow you to create a "Master" display, and additional modules can hook it and add addtional displays for your view. In the screenshot below, you see we have additional displays of Attachment, Content pane, Context, and Feed in addition to the Block and Page displays.
All of our sites already have some sort of "Page" content type, for basic content of the site. In this page content type, we add fields, set meta descriptions, get added to the xml sitemap, and include the pages in Drupal's core search. When you create a view page, we only get the output as a url, we miss the benefit of having a "Page" node at that url.
The Metatag: Views (metatag_views) module can provide a way to add metatags to the view page, but more tags like Open Graph and Twitter Card Image tags are much harder to set up without additional fields, that you most likely already configured on page nodes. Adding a "Featured Image" field on your page node, is a great way to get a token to add your images to the og:image and twittercard:image meta tags.
The other huge benefit is for the users of your site who use search. At a recent meetup in Chicago, a very smart developer presented a scenario where a user was bypassing the "Events" link in the main menu, and searching for for the term "events". Because they had created a view page, the events page was not available to users who search, and were getting no results.
To gain the benefit of having a page node, and having including a view, first create a Page node, and configure as needed. Then create your view. You have a few different options on how to add your view to the page.
My suggestion was to create a page node for events, then add his view to it. With Drupal, there are many different ways to achieve the same results. Here are a few different ways to add a view to page nodes.
Blocks
Create a View display that is a block, and add the page you want to the block visibility settings.
Context
Similar to block visibility settings, you can add the block to your page node using the Context module.
Panels: Page Manager or Panelizer
If you are using Panels, you can create a Content Pane from the view, and add it to the url using Page Manager or Panelizer.
To sum up
Using views to create a block or pane to add to a page node is preferred to creating a page with views. If you create a page node, and add your view to it, you get the following benefits:
-
Metatag and Tokens created from fields on the page node.
-
Pathauto URL pattern of page node
-
Addition of url (Page node) to sitemap.xml
-
Inclusion in Drupal core search.
Screenshots are from Drupal 7, where Views was a contrib module, but with the inclusion of Views in core of Drupal 8, this idea will continue to exist.