Hello together!
I have integrated the search function from the cookbook:
It worked right away. However, “type: blocks
” are also searched and JSON code appears in the search results:
[{"content":{"text":" Lorem ipsum dolor sit amet elementum por …
How and where do I adjust the code to remove JSON code from the results? I have not found a solution here in the forum.
/site/templates/search.php
<ul>
<?php foreach ($results as $result): ?>
<li>
<a href="<?= $result->url() ?>">
<?= $result->text() ?>
</a>
</li>
<?php endforeach ?>
</ul>
/site/controllers/search.php
<?php
return function ($site) {
$query = get('q');
$results = $site->search($query, 'title|headline|subheadline|text');
return [
'query' => $query,
'results' => $results,
];
};
Additionally, I would like to show the number of search results:
“12 hits were found”
How do I read out the total number of hits found?
thank you!