List content¶
To render a list of content items, for example, content in a folder, or blog posts in a blog, you can use one of two methods:
- use a Query type
- create a content type with a Content Query Field
List children with Query type¶
The following example shows how to render the children of a Folder.
First, in the content view configuration, add the following view for the Folder content type:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
controller
defines which controller is used to render the view.
In this example, it's the default Query controller.
1 |
|
params
define that you want to render the content by using the Children
Query type.
This Query type automatically finds the children of the current content item.
The results of the query are placed in the items
variable, which you can use in templates.
Then, place the following template in templates/themes/<my_theme>/full/folder.html.twig
:
1 2 3 |
|
This template uses the ibexa_render()
Twig function to render every child of the folder with the default template for the line
view.
List children in Content query Field¶
A Content query Field is a field that defines a query. The following example shows how to use a Content query field to render a Blog with its Blog Post children.
First, create a Blog content type that contains a Content query field with the identifier query
.
In the Field definition, select "Children" as the Query type.
Provide the content
parameter that the Query type requires:
1 |
|
You can paginate the query results by checking the Enable pagination box and selecting a limit of results per page.
Select the content type you want to render (in this case, Blog Post) as Returned type.
Then, in the content view configuration, add the configuration under content_query_field
:
1 2 3 4 5 6 7 |
|
The match
configuration matches both the content type and the identifier of the Content query field.
Finally, in the template templates/themes/<my_theme/content_query/blog_posts.html.twig
, render all results of the query:
1 2 3 |
|