You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Show selected content on the front page by criterion.
12
+
# Create a dynamic front page listing
15
13
16
14
```{card}
17
15
In this part you will:
@@ -26,9 +24,7 @@ Tools and techniques covered:
26
24
27
25
````{card} Frontend chapter
28
26
29
-
Despite this is a frontend chapter, we are working on **backend** code in `ploneconf.site`.
30
-
31
-
Checkout `ploneconf.site` at tag "initial":
27
+
Check out `mastering-plone-project` at tag `behaviors_1`:
32
28
33
29
```shell
34
30
git checkout behaviors_1
@@ -44,49 +40,60 @@ More info in {doc}`code`
44
40
````
45
41
46
42
47
-
We prepared a behavior for content types to store the information if the content should be featured in the previous chapter.
43
+
In the previous chapter, we prepared a behavior for content types to store the choice of whether the content should be featured.
48
44
And we enhanced the catalog search by adding index and metadata "featured".
49
45
Now we turn this into a criterion for a listing block that shows featured content.
50
46
51
47
52
48
(volto-frontpage-criterion-label)=
53
49
54
-
## Add Index as collection criterion
50
+
## Query criteria
55
51
56
-
To understand why we need a collection criterion for a dynamic front page in Volto and what a collection criterion is, we have to look at the listing block of Volto.
52
+
To understand what a query criterion is, we have to look at the listing block of Volto.
57
53
58
54
```{figure} _static/volto_frontpage.png
59
55
:alt: Listing Block sidebar
60
56
```
61
57
62
58
In the sidebar, we see the {guilabel}`Criteria` select menu, and if we click there, it'll show some of the selectable criteria ordered in categories like the following:
63
59
64
-
-`Metadata` contains indexes that are counting as metadata like Type (means Portal Types) and Review State
65
-
-`Text` contains indexes that are counting as text-data like Description and Searchable Text
66
-
-`Dates` contains indexes which are working with date-data like Effective Date and Creation Date
60
+
-`Metadata` contains indexes that are counting as metadata like Type (meaning content type) and Review State
61
+
-`Text` contains indexes that are counting as text data like Description and Searchable Text
62
+
-`Dates` contains indexes which are working with date data like Effective Date and Creation Date
63
+
64
+
These criteria control how the listing is filtered to include the content items we want to show.
67
65
68
-
To get all talks we marked as `featured` we have to get the listing block to recognize our newly created index.
66
+
## Add an index to the query criteria
67
+
68
+
To get all talks we marked as `featured`, we have to get the listing block to recognize our newly created index.
69
69
This means we have to add our index to the collection criteria, to be selectable by the editor.
70
70
71
-
To add our new index as a criterion to be applicable in a listing block or a collection, we have to switch to our `backend`. There we have to create a plone.app.registry record for our index. This can be achieved by adding a new file {file}`profiles/default/registry/querystring.xml`:
71
+
To add our new index as a criterion to be applicable in a listing block or a collection, we have to create a plone.app.registry record for our index.
72
+
This can be achieved by adding a new file {file}`backend/src/ploneconf/site/profiles/default/registry/querystring.xml`:
@@ -95,11 +102,11 @@ To add our new index as a criterion to be applicable in a listing block or a col
95
102
To understand this code snippet, we have to know the information and tags we are using:
96
103
97
104
- The prefix `plone.app.querystring.field.featured` refers to the featured index we just created.
98
-
- The operations elements define the provided criterion values to filter the listing.
105
+
- The operations elements define which operations can be used when filtering by this index.
99
106
- The group value defines the group under which the entry shows up in the selection widget, in our case `Metadata`.
100
107
101
-
```{note}
102
-
For a list of existing QueryField declarations and operations see https://github.com/plone/plone.app.querystring/blob/master/plone/app/querystring/profiles/default/registry.xml
108
+
```{tip}
109
+
For a list of Plone's default querystring criteria and declarations and operations, see https://github.com/plone/plone.app.querystring/blob/master/plone/app/querystring/profiles/default/registry.xml
103
110
```
104
111
105
112
We can now restart the instance and re-install the add-on.
@@ -108,8 +115,8 @@ We can now restart the instance and re-install the add-on.
108
115
## Add a listing block to show the featured content
109
116
110
117
Now we go back to our frontend.
111
-
To create a new listing block on the front-page we have to click on `edit` and then create one new block.
112
-
Now you choose the block `Listing` from the menu:
118
+
To create a new listing block on the frontpage we have to click on `edit` and then create one new block.
119
+
Choose the block `Listing` from the menu:
113
120
114
121
```{figure} _static/volto_frontpage_1.png
115
122
:alt: Most used blocks in Volto
@@ -123,9 +130,4 @@ You can select the 'featured' criterion:
123
130
:align: left
124
131
```
125
132
126
-
## Outlook: Block variations
127
-
128
-
The listing block comes with default variations for the display.
129
-
The editor can choose from these variations to change the template for the listing: with thumbnail image or without, etc..
130
-
Your project maybe needs a custom template. The way to go would be to create an additional variation of the listing block.
131
-
See {ref}`plone6docs:extensions-block-variations` for more information.
133
+
Now the listing shows only the items in the site that have the `featured` checkbox checked.
0 commit comments