官术网_书友最值得收藏!

  • Drupal 8 Blueprints
  • Alex Burrows
  • 465字
  • 2021-07-03 00:03:27

Understanding views

Now that we have set up our first view, let's get it to display some content.

We will create a latest news block, which will show our latest five news posts. By default, the view will display any content that is related to the content type, and it will only show the title. We will change this:

Fig 1.20: Views display page

In Fig 1.20, we can see there are three columns and in each column, there is an individual section. For now, we will just go through what we need for our Latest news block, but later we will go into more depth.

In views, we have Displays, these are the different ways that content is displayed. For the latest news and related news, we will, however, use the Display type of block. We will go into more detail later when we build our news listing page:

  • TITLE: This is the title that will appear in our display.
  • FORMAT: This is split into two sections:
    • Format: This is, by default, the type of layout, along with settings, for this format.
    • Show: This allows us to define how we want the content to be shown; we can either show based on a view mode or add fields to the view display.
  • FIELDS: If we select the mentioned Format type to be fields, we will be able to add fields from our content type into this display. This allows us to customize our fields and how they are shown, and it ignores our view mode we created earlier.
  • FILTER CRITERIA: We can set different filters that will depend on what content is to be shown. By default, Published is set to Yes.
  • SORT CRITERIA: We can sort our content to display in many ways.

This is the first part we will cover. We want to create a very simple block that uses our default teaser view mode. To do this, we must click on the value next to Show; in this case, its Fields.

When we do this, a modal will appear with three radio buttons:

Fig 1.21

From Fig 1.21, we want to select Content. After we click on Apply, we will be shown a drop-down list that contains all the types of view modes we can have. We want to select the Teaser view mode.

When we apply this, we will see our news article along with its title, post information (author and timestamp of when it was created), and our Read more link in the preview. We see the post information because we had Show submission information checked inside the content type settings. Now that we have created our first view, let's place it on our sidebar.

主站蜘蛛池模板: 定陶县| 连山| 乌拉特后旗| 桐城市| 马鞍山市| 东兰县| 松江区| 旌德县| 乌鲁木齐县| 临泽县| 揭阳市| 奉贤区| 当涂县| 贵南县| 富锦市| 获嘉县| 枣强县| 玉溪市| 碌曲县| 蚌埠市| 昭通市| 青川县| 遂宁市| 天水市| 东阿县| 华容县| 辽源市| 六盘水市| 柳林县| 高州市| 台南市| 淮阳县| 南皮县| 广宁县| 浮山县| 崇文区| 兰考县| 类乌齐县| 大渡口区| 焉耆| 治县。|