drupal views
Views is one of the most popular Drupal modules with over 5 million downloads and over 700 thousand sites that report using it. It is so popular that Drupal 8 will ship with Views in core as part of an exciting and welcomed initiative of the Drupal 8 release process.
Views是最受欢迎的Drupal模块之一,下载量超过500万,报告使用它的网站超过70万。 它是如此流行,以至于Drupal 8发行过程中激动人心的举措的一部分,将把Views作为核心附带。
This is an introductory tutorial to the world of Views and how you can use this great module to create listings of content. There are a few smaller topics that I will cover as part of this tutorial. First, we’ll see how to get started and create a View. Then we will see what kind of listings and content formats are available for us out of the box.
这是Views世界的入门教程,以及如何使用这个出色的模块创建内容清单。 在本教程中,我将介绍一些较小的主题。 首先,我们将了解如何入门和创建视图。 然后,我们将开箱即用地查看什么样的列表和内容格式。
Once we choose how the View will look like, we will cover a bit of filtering and sorting. These options are used to make sure we display only the right content and in the order we want it to appear. Sounds exciting?
选择View的外观后,我们将介绍一些过滤和排序。 这些选项用于确保我们仅显示正确的内容并按希望显示的顺序显示。 听起来很令人兴奋?
Let’s dive right in.
让我们潜入。
Installing Views is like installing any other module. I’m not going to cover the process of installing Drupal modules but rather point you to the definitive guide on Drupal.org.
安装Views就像安装其他模块一样。 我将不介绍Drupal模块的安装过程,而是为您提供Drupal.org上的权威指南 。
If you know how to use Drush (which I recommend wholeheartedly to learn), you can run two simple commands and you’re good to go:
如果您知道如何使用Drush(我全力推荐您学习),则可以运行两个简单的命令,您可以轻松进行以下操作:
drush dl views drush en views views_ui -yThis will download and enable all the necessary modules (including CTools which is a dependency).
这将下载并启用所有必需的模块(包括依赖的CTools)。
Now that we have Views installed, we can navigate to admin/structure/views to get an overview of all the existing Views on the site. You’ll notice a few disabled ones that come out of the box. We won’t go into those but it’s good to know they are there. Front page and Taxonomy Term are particularly interesting as they emulate and replace default Drupal behaviors.
现在我们已经安装了Views,我们可以导航到admin/structure/views以获取站点上所有现有Views的概述。 您会发现开箱即用的一些残疾人。 我们不会涉及这些内容,但是很高兴知道它们在那里。 主页和分类术语特别有趣,因为它们可以模拟并替换默认的Drupal行为。
What I want to do going forward is to create a View and play around to illustrate how you can start using it. So go ahead and click the Add new view link at the top to get to the View creation form.
我要继续做的是创建一个View并进行演示以说明如何开始使用它。 因此,继续并单击顶部的“ 添加新视图”链接以进入“视图创建”表单。
Here we’ll set a View name and inside the first fieldset we can already filter on what kind of information the View will show.
在这里,我们将设置一个视图名称,并且在第一个字段集中,我们已经可以根据视图将显示的信息进行过滤。
We will select to show Content (nodes) but you’ll notice also other entities (terms, users etc). Please note that the choice you make in this select box cannot be changed later. Since we chose Content, we get also the option of choosing which content type. For now let’s go with Article but know that you can change this later on when editing the View.
我们将选择显示“ Content (节点),但您还会注意到其他实体(术语,用户等)。 请注意,您在此选择框中所做的选择以后将无法更改。 由于选择了Content ,因此我们还可以选择哪种内容类型。 现在,让我们继续使用Article,但要知道您稍后可以在编辑View时进行更改。
Additionally, since we chose the Article content type which has a Tags field that references taxonomy terms in the vocabulary with the same name, we can also do an immediate filtering based on this. We won’t, however know that it is possible (both now and later when editing the View). And lastly, we can sort the listing by a few of the already available criteria, but we won’t do that either yet.
此外,由于我们选择了具有“ Tags字段的“ Article内容类型,该Tags字段引用了词汇表中具有相同名称的分类术语,因此我们也可以基于此立即进行过滤。 但是,我们不知道这是可能的(现在和以后编辑视图时都可以)。 最后,我们可以按照一些可用的条件对列表进行排序,但我们也不会这样做。
Below the fieldset we just edited, we see 2 more fieldsets that give us the possibility to create a page and a block. They are shortcuts to creating displays for our View.
在我们刚刚编辑的字段集的下面,我们看到了另外两个字段集,这使我们可以创建页面和块。 它们是为我们的视图创建显示的快捷方式。
Any View can contain multiple displays of different types (page, block, feed etc). Some are available out of the box and some are provided by other contributed modules. Therefore you can create a single View that displays the same content in multiple ways, using different formats, filters etc.
任何视图都可以包含多个不同类型的displays (页面,块,提要等)。 有些是开箱即用的,有些是其他贡献模块提供的。 因此,您可以创建一个使用不同格式,过滤器等以多种方式显示相同内容的视图。
For this article, we will stick to the Page display and we will create it at the next step (just so you see the whole process). So leave those 2 checkboxes unchecked, and click Continue and edit.
对于本文,我们将坚持使用“ 页面”显示,然后在下一步中创建它(以便您看到整个过程)。 因此,请取消选中这2个复选框,然后单击继续并编辑 。
You will be taken to the main View edit page where I recommend clicking the Save button as the View is not yet saved before you do this.
您将被带到“视图”主编辑页面,在此建议您单击“ 保存”按钮,因为尚未保存视图。
On this page you’ll notice at the top a Displays bar which contains one called Master. We want to create a page with a path where we can see our listing. So click Add, select Page and specify a new display name. Next you can also choose a page title by clicking on None under the Title fieldset.
在此页面上,您会在顶部看到一个Displays栏,其中包含一个称为Master的Displays栏。 我们想要创建一个页面,该页面带有一个可以查看清单的路径。 因此,单击Add ,选择Page并指定一个新的显示名称。 接下来,您还可以通过单击“ 标题”字段集下的“ None来选择页面标题。
There is one important thing to note here that will serve you well in the future. When you make changes like the one you just made, you’ll get the choice of having it applied to only this display or all the others (see the image below). You have to be careful because the default selection is All displays. It’s easy to forget and that can cause problems if you have multiple displays. so keep this in mind and make sure you make changes to the displays you want to make changes to.
这里有一件重要的事情要注意,它将在将来为您服务。 当您像刚进行的更改一样进行更改时,您可以选择仅将其应用于此显示或所有其他显示(请参见下图)。 您必须小心,因为默认选择是“ All displays 。 容易忘记,如果有多个显示器,可能会引起问题。 所以记住这一点,并确保你改变你想改变的显示器。
Before going through the rest of the settings, you’ll have to specify a path for the View page. Views will need to register it with Drupal and won’t let you save the View without one. So under Page settings click on the No path is set to specify one. You can then also place it in a menu and specify an access rule for the page.
在进行其余设置之前,您必须为“查看”页面指定路径。 视图将需要在Drupal中注册,并且不允许您保存视图。 因此,在“ 页面设置”下,单击“ No path is set以指定一个。 然后,您也可以将其放置在菜单中并为页面指定访问规则。
Under the Format fieldset we have some important options that deal with how the View is displayed and what particularly from the content is displayed. Out of the box you have a few formats you can choose from (and some settings for each) but we will go with the default one for now: unformatted list. This is the simplest one but I do encourage you to play around and experiment with the others.
在格式字段集,我们有应对如何查看显示什么特别从内容显示一些重要的选项。 开箱即用,您可以选择几种格式(每种格式都有一些设置),但现在我们将使用默认格式:无格式列表。 这是最简单的一种,但我鼓励您与其他人一起尝试。
But now that we selected the format, let’s see what will actually be formatted. By default, it is fields. This means that you choose a number of Drupal fields (either entity properties or fields declared through the Field UI) and they get displayed for every article. This is what we will choose going forward but I want to tell you also about the other option that comes with Views: content.
但是,既然我们选择了格式,让我们看看实际要格式化的内容。 默认情况下,它是字段。 这意味着您选择了许多Drupal字段(实体属性或通过Field UI声明的字段),并且每篇文章都会显示它们。 这是我们将继续选择的内容,但我也想告诉您有关Views的另一个选项: content 。
Each content type in Drupal 7 comes with a few view modes (full, teaser, RSS, etc). Using the Display Suite module you can define even more. And for each view mode you can specify a different way the fields get displayed. For example you will have a different image style for the image in the teaser than in the full view mode.
Drupal 7中的每种内容类型都带有一些查看模式(完整,预告片,RSS等)。 使用Display Suite模块,您可以定义更多。 对于每种查看模式,您可以指定显示字段的不同方式。 例如,对于预告片中的图像,您将具有与全视图模式下不同的图像样式。
This is what the content alternative to fields refers to in Views. You can choose the node to be displayed using a particular view mode. And that can be powerful. But let’s move forward with using fields because this keeps us in the realm of Views when it comes to preparing the output of each individual View row.
这就是视图中fields替代content所指的content 。 您可以使用特定的视图模式选择要显示的节点。 那可能很强大。 但是,让我们继续使用字段,因为在准备每个单独的View行的输出时,这使我们进入了Views领域。
Now that we decided to go with the fields option, you’ll notice already in the preview area at the bottom of the page a list of article titles. That’s because by default, Views will include the title field since at least one is required. To add others, click on the Add button under Fields. You’ll be prompted with an overlay where you can search and select fields to add.
现在,我们决定使用fields选项,您将在页面底部的预览区域中注意到文章标题列表。 这是因为默认情况下,由于至少需要一个视图,因此视图将包含标题字段。 要添加其他内容,请点击Fields下的Add按钮。 系统会提示您一个覆盖图,您可以在其中搜索和选择要添加的字段。
Different field types have different options available and unfortunately we cannot go over all of them here. But let’s set out a small goal and try to accomplish it: article node teasers that show the title, Body summary and image. So look let’s look for the default Body and image fields that come with the Article content type. These appear as Content: Body and Content: Image so check the box next to them and apply.
不同的字段类型具有不同的可用选项,但是不幸的是,我们在这里不能对它们进行全部介绍。 但让我们设定一个小目标并尝试实现它:显示标题,正文摘要和图像的文章节点预告片。 因此,让我们寻找“文章”内容类型随附的默认“正文”和“图像”字段。 这些Content: Body显示为“ Content: Body和“ Content: Image因此选中它们旁边的框并应用。
You’ll have to configure both of these fields one at a time. For the Body we can uncheck the box next to Create a label and under Formatter select the Summary or trimmed together with a custom trim length if you want.
您必须一次配置这两个字段。 对于主体,我们可以取消选中“ Create a label ”旁边的框,然后在“ 格式器”下选择“ Summary or trimmed根据需要与自定义修剪长度一起修剪。
The next 3 collapsed fieldsets are quite advanced and available for most other field types as well. We cannot cover them in this tutorial but here is a quick summary. Under Style settings you can manipulate the HTML that gets rendered for this individual field on every row. Under No results behavior you can specify a value to display in case there is no value inside the field itself. And under Rewrite results you have a lot of options that relate to altering the content of the field being displayed. Here you can merge fields together, create links, strip tags and other powerful actions.
接下来的3个折叠的字段集相当高级,也可用于大多数其他字段类型。 我们不能在本教程中介绍它们,但是这里是一个简短的摘要。 在“ Style settings您可以操纵在每一行上为此单个字段呈现HTML。 在“ No results behavior您可以指定要显示的值,以防字段本身内没有值。 在“ Rewrite results ”下,您具有许多与更改所显示字段内容有关的选项。 在这里,您可以将字段合并在一起,创建链接,删除标签和其他强大的操作。
After finishing the Body, you’ll have to repeat the process for the image field. I suggest again removing the label and since we want the image to be for a teaser, let’s select the thumbnail image style. We can also link the image to the content. After saving these settings as well, check the preview below. You should see the title, Body and image for each Article node. If you want to change the order of the fields, click the little arrow next to the Add button you just clicked and choose Rearrange. Then you can drag’n’drop them into position.
完成主体后,您将不得不对图像字段重复该过程。 我建议再次删除标签,由于我们希望图像用于预告片,因此让我们选择缩略图图像样式。 我们还可以将图像链接到内容。 保存完这些设置后,请检查以下预览。 您应该看到每个Article节点的标题,正文和图像。 如果要更改字段的顺序,请单击刚刚单击的Add按钮旁边的小箭头,然后选择Rearrange 。 然后,您可以将它们拖放到适当的位置。
Although this is far from over and there’s plenty of editing and styling to be done for any real website, let’s say we are happy with the output and we can move on.
尽管这还远远没有结束,并且对于任何真实的网站都需要进行大量的编辑和样式设置,但可以说我们对输出感到满意并且可以继续前进。
Below the Fields, you can see the Filter criteria section which already contains two filters (you can click on them and see their options). The first one is a filter on the node status property and shows only content that is published. The second one filters on the type property and shows only the nodes of the type article. Here we can make changes if we want to change or include other content types.
在“ Fields下方,您可以看到“ Filter criteria部分,该部分已经包含两个过滤器(您可以单击它们并查看其选项)。 第一个是节点状态属性上的过滤器,仅显示已发布的内容。 第二个过滤器对type属性进行过滤,仅显示type article的节点。 如果要更改或包括其他内容类型,可以在此处进行更改。
Filters can also be exposed to end users by checking the box Expose this filter to visitors, to allow them to change it. So for instance if we wanted end users to choose which content types should be included, we could edit the filter and enable this functionality.
通过选中复选框Expose this filter to visitors, to allow them to change it也可以向最终用户显示Expose this filter to visitors, to allow them to change it 。 因此,例如,如果我们希望最终用户选择应包括哪些内容类型,则可以编辑过滤器并启用此功能。
Under the Advanced fieldset at the right of the page you can also add contextual filters. These are very powerful when you need filters to be passed dynamically from the global scope, URL or other contexts. It’s an advanced feature that we cannot cover here, but keep in mind that it’s there.
在页面右侧的“ Advanced字段集下,您还可以添加上下文过滤器。 当您需要从全局范围,URL或其他上下文动态传递过滤器时,这些功能非常强大。 这是一个高级功能,我们无法在此介绍,但请记住它已经在这里。
In the Sort criteria section you can add fields to be used for sorting the View. Let’s look for the node authoring date (Content: Post date) and add it to the View to sort the listing in a Descending order.
在“ Sort criteria部分中,您可以添加用于对视图进行排序的字段。 让我们寻找节点的创作日期( Content: Post date ),并将其添加到View中,以降序对列表进行排序。
Note that you can also expose these fields to the end user and let them perform their own sorting.
请注意,您还可以将这些字段公开给最终用户,并让他们执行自己的排序。
So here we are. We put together a simple View that displays some basic information about all the articles on the site. In doing so, we’ve seen how to create a View and what are some of the possibilities regarding its format. We discussed displays and we created our very own page that renders the View. We also saw how we can add fields and what’s the difference between fields and content when it comes to Views. And finally, we looked at which basic filter and sorting criteria exist and how they work.
所以我们到了。 我们将一个简单的视图放在一起,显示有关该网站上所有文章的一些基本信息。 在此过程中,我们了解了如何创建视图以及有关其格式的一些可能性。 我们讨论了显示,并创建了自己的呈现视图的页面。 我们还看到了如何添加字段以及涉及视图的fields和content之间的区别。 最后,我们研究了存在哪些基本过滤器和排序标准以及它们如何工作。
Unfortunately, we also only just scratched the surface of Views. As an experienced user of Views I feel like I covered nothing of its power. This is because it is so complex that the steps we took pale in comparison. But you have to start with the basics and understand the fundamental concepts before you move on to more exciting functionality.
不幸的是,我们也只是刮擦了Views的表面。 作为经验丰富的Views用户,我觉得自己对此一无所知。 这是因为它是如此复杂,以至于我们所采取的步骤相形见pale。 但是,在继续使用更令人兴奋的功能之前,您必须先从基础知识入手,并了解基本概念。
There are many other features and options in Views that really make it indispensable for almost any Drupal site. I therefore recommend you spend some good time on learning it if you want to work with Drupal in an efficient way.
Views中还有许多其他功能和选项,实际上使它对于几乎所有Drupal网站都必不可少。 因此,如果您想以有效的方式与Drupal一起工作,我建议您花一些时间学习它。
翻译自: https://www.sitepoint.com/introduction-views-3-drupal-7/
drupal views
相关资源:jdk-8u281-windows-x64.exe