- Documentation >
- Guide >
- Search >
- Search Criteria reference >
- Ancestor
Ancestor Criterion
The Ancestor
Search Criterion
searches for content that is an ancestor of the provided Location, including this Location.
Arguments
value
- array of Location pathStrings
Example
| $query->query = new Criterion\Ancestor([$this->locationService->loadLocation(62)->pathString]);
|
Use case
You can use the Ancestor Search Criterion to create a list of breadcrumbs leading to the Location:
1
2
3
4
5
6
7
8
9
10
11
12 | $query = new LocationQuery();
$query->query = new Criterion\Ancestor([$this->locationService->loadLocation($locationId)->pathString]);
$results = $this->searchService->findLocations($query);
$breadcrumbs = [];
foreach ($results->searchHits as $searchHit) {
$breadcrumbs[] = $searchHit;
}
return $this->render('parts/breadcrumbs.html.twig', [
'breadcrumbs' => $breadcrumbs,
]);
|
| {% for breadcrumb in breadcrumbs %}
{% if not loop.first %} -> {% endif %}
{% if not loop.last %}
<a href="{{ ez_path( breadcrumb.valueObject ) }}">{{ breadcrumb.valueObject.contentInfo.name }}</a>
{% else %}
{{ breadcrumb.valueObject.contentInfo.name }}
{% endif %}
{% endfor %}
|