Hey,
I have integrated the search function on a page search.php.
If the user searches for something, the matching results are displayed.
But is it possible to display a special text when there are no matching results?
templates > search.php
<form>
<input type="search" placeholder="Suchbegriff eingeben" name="q" value="<?= html($query) ?>">
<input type="submit" value="Suche">
</form>
<?php if ($results->isNotEmpty()): ?>
<h3>Suchergebnisse für: <?= html($query) ?></h3>
<?php endif ?>
<?php foreach ($results as $result): ?>
<a href="<?= $result->url() ?>">
<?= $result->startbild()->toFile() ?>
<?= $result->title() ?>
</a>
<?php endforeach ?>
controllers > search.php
<?php
return function ($site) {
$query = get('q');
$results = $site->index()->filterBy('template', 'not in', ['search'])->search($query, ['words' => true]);
return [
'query' => $query,
'results' => $results,
];
};
Thank you