I use two templates on my website. The site based on baseblog theme and there is a search function to search in blog articles. As the second template knowledge base is used. There is a basic search functionality, that I want to use only therefore.
[...]
04-support
05-blog
[some hidden folders...]
Both templates are using different styles and I want to show two different result pages. Is this possible?
I have different header, content and footer for both of them.
<?php snippet('header') ?>
<?php snippet('menu') ?>
<main role="main">
<?php $countItems = $pagination->countItems();
if($results) {
echo '<h1 class="result">';
if($countItems == 0) {
echo 'No results';
}
elseif($countItems == 1) {
echo $countItems , ' top result';
}
else {
echo $countItems , ' results';
}
echo ' for “<mark>' , $query , '</mark>”</h1>';
} ?>
<?php if($results->count() != 0): ?>
<ul class="results">
<?php foreach($results as $result): ?>
<li>
<h2><a href="<?= $result->url() ?>"><?= $result->title()->html() ?></a></h2>
<div class="meta">
<time datetime="<?= $result->date('c') ?>"><?= $result->date('%A, %e. %B %Y'); ?></time>
<?php if ($result->tags() != ''): ?> |
<ul class="tags">
<?php foreach(str::split($result->tags()) as $tag): ?>
<li><a href="<?= url('tag:' . urlencode($tag)) ?>">#<?= $tag ?></a></li>
<?php endforeach ?>
</ul>
<?php endif ?>
</div>
</li>
<?php endforeach ?>
</ul>
<?php endif ?>
<?php if($pagination->hasPages()): // pagination ?>
<nav class="pagination cf">
<?php if($pagination->hasPrevPage()): ?>
<a class="button prev" href="<?= $pagination->prevPageURL() ?>">‹‹ newer results</a>
<?php endif ?>
<?php if($pagination->hasNextPage()): ?>
<a class="button next" href="<?= $pagination->nextPageURL() ?>">older results ››</a>
<?php endif ?>
</nav>
<?php endif ?>
</main>
<?php snippet('footer') ?>
How can I detect the calling search function to choose the right header, footer… in the template search.php?
How do I have to modify the controller file.
<?php
return function($site, $pages, $page) {
$query = get('q');
// baseblog
if (page('blog')) {
$results = page('blog')->search($query, array('words' => true))
->visible()
->sortBy('date', 'desc')
->paginate(10);
return array(
'query' => $query,
'results' => $results,
'pagination' => $results->pagination()
);
// knowledge base
} elseif (page('support')) {
$results = page('support')->visible()
->search($query, 'title|text')
->paginate(10);
/*
$results = $site->index()
->visible()
->search($query, 'title|text');
*/
return array(
'query' => $query,
'results' => $results,
'pagination' => $results->pagination()
);
}
};
So that it works. At the moment it works for blog entries, but not for the support page. Always showing “no results”.
Thanks for your advice and help.