Skip to content

List content

To render a list of Content items, for example, content in a folder, blog posts in a blog, and so on, you can use one of two methods:

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
            content_view:
                full:
                    folder:
                        controller: ez_query::contentQueryAction
                        template: '@ezdesign/full/folder.html.twig'
                        params:
                            query:
                                query_type: 'Children'
                                parameters:
                                    content: '@=content'
                                assign_results_to: items
                                limit: 3
                        match:
                            Identifier\ContentType: folder

controller defines which controller is used to render the view. In this example, it is the default Query controller.

1
                        controller: ez_query::contentQueryAction

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
{% for item in items.searchHits %}
    {{ ez_render(item.valueObject, {'viewType': 'line'}) }}
{% endfor %}

This template uses the ez_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
content: '@=content'

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
            content_view:
                content_query_field:
                    blog:
                        template: '@ezdesign/content_query/blog_posts.html.twig'
                        match:
                            Identifier\ContentType: blog
                            '@EzSystems\EzPlatformQueryFieldType\eZ\ContentView\FieldDefinitionIdentifierMatcher': query

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
{% for item in items.searchHits %}
    {{ ez_render(item.valueObject, {'viewType': 'line'}) }}
{% endfor %}