With content queries you can find and render specific content according to criteria that you define.
You can use queries to list or embed Content items, such as:
Content queries use the built-in Query controller which simplifies querying. For more complex cases, you can build custom controllers.
You can also write custom Query types for the cases that are not covered by the built-in ones.
Query type configuration¶
To use a Query type, select the Query controller (
ez_query) in the content view configuration
and select the Query type under
1 2 3 4 5 6 7 8 9 10 11
Use one of the following Query controller methods:
locationQueryActionruns a Location Search
contentQueryActionruns a content Search
contentInfoQueryActionruns a ContentInfo search
PagerFantaobject and can be used to quickly paginate query results
See the Search documentation page for more details about different types of search.
All Query types take the following parameters:
query_typeis the name of the Query type to use.
- arbitrary values
- expressions based on the
viewvariables. For example,
@=location.idis evaluated to the current Location's ID.
assign_results_todeclares the Twig variable that contains the search results.
Search results are a
SearchResult object, which contains
To get the content or Locations that are in search results, you access the
To paginate the results of a query, use the
pagingQueryAction of the Query controller
and assign a limit per page in
1 2 3 4 5 6 7 8 9 10 11 12 13 14
pagerfanta variable to render pagination controls:
1 2 3 4 5 6 7 8
Content query Field¶
The Content query Field is a Field that defines a query. The results of the query are available in the Field value.
Select the Content Type of items you want to return in the Returned type dropdown.
To take it into account, your Query type must filter on the Content Type.
Provide the selected Content Type through the
Select Enable pagination and set the number of items per page to paginate the results.
You can override the pagination settings from Field definition
by setting the
itemsPerPage parameters when rendering the Content query Field:
1 2 3 4 5 6
You can also define an offset for the results. Provide the offset in the Query type, or in parameters:
If pagination is disabled and an offset value is defined, the query's offset is added to the offset calculated for a page.
For example, with
offset 5 and
itemsPerPage 10, the first page starts with 5, the second page starts with 15, and so on.
Without offset defined, pagination defines the starting number for each page.
For example, with
itemsPerPage 10, first page starts with 0, second page starts with 10, and so on.
The following variables are available in parameter expressions:
returnedType- the identifier of the Content Type selected in the Returned type dropdown
content- the current Content item
location- the current Location of the Content item
mainLocation- the main Location of the Content item
contentInfo- the current Content item's ContentInfo
Content view configuration¶
To render a Content query Field, in the content view configuration, use the
content_query_field view type:
1 2 3 4 5 6 7
The identifier of the Content query Field must be matched by
Query results are provided to the template in the
See List content for an example of using the Content query Field.