Hi!
Is it possible to have search results also display specifically a page’s structure field row?
For example: There’s a page “comics” with a structure field “characters” which contains for example the columns “name” and “date”.
- The user searches for “Mickey Mouse”
- The page uid in which the string “Mickey Mouse” is found is being returned/displayed
- Now I can use $page->title() on the page
However, can I also only display the single structure field row which contains the string “Mickey Mouse”? Or just the entire page?
My search controller is the following:
return function ($site) {
$query = get('q');
$results = $site->search($query)->listed();
return [
'query' => $query,
'results' => $results
];
};
The “characters” structure field would be:
# | N a m e | D a t e |
-----------------------
1 | Mickey Mouse | 1950
-----------------------
2 | Donald Duc k | 1960
-----------------------
3 | Buuugs Bunny | 1980
My foreach
is:
(sorry for the structure)
<?php foreach ($results as $result): ?>
<?php if($result->template() == "comics"): ?>
<?php $rows = $result->characters()->toStructure(); foreach ($rows as $row): ?>
<?php if(in_array($query, $row)): ?>
<?= $row->name() . $row->date() ?>
<?php endif ?>
<?php endforeach ?>
<?php endif ?>
<?php endforeach ?>
Thanks for any input!