I didn’t use a custom tpl to this point, but that’s where the problem was coming from.
The standard tpl uses an output filter
href="[[+link:is=``:then=`[[~[[+id]]]]`:else=`[[+link]]`]]"
that caused the problem. Using a custom tpl now with just [[+link]] works. Thanks @jako
I just need to find out now, how to use two different facets in the same SimpleSearch. Right now I put the hook into the default facet, but in this case I can’t give the agenda entries a different color for example. But that’s a different topic.
Here is the working code now.
snippet/posthook (agendaSearch):
<?php
//110 from $modx->makeUrl(110, '', $eventlink) is the event detail resource id
$results = [];
$corePath = $modx->getOption('agenda.core_path', null, $modx->getOption('core_path') . 'components/agenda/');
$agenda = $modx->getService('agenda', 'Agenda', $corePath . 'model/agenda/', [
'core_path' => $corePath
] );
$c = $modx->newQuery( 'AgendaEvents' );
$c->select( 'id, title' );
$c->where( [
'title:LIKE' => '%' . $search . '%',
'OR:content:LIKE' => '%' . $search . '%'
] );
$count = $modx->getCount( 'AgendaEvents', $c );
$c->limit( $limit, $offset );
$events = $modx->getCollection( 'AgendaEvents', $c );
foreach ( $events as $event ) {
$eventlink = 'event=' . $event->get('id');
$results[] = [
'pagetitle' => $event->get('title'),
'link' => $modx->makeUrl(110, '', $eventlink),
'excerpt' => '',
];
}
$hook->addFacet( 'default', $results, $count );
return true;
chunk (CustomSearchResult):
<div class="simplesearch-result">
<h3>[[+idx]]. <a href="[[+link]]" title="[[+longtitle]]">[[+pagetitle]]</a></h3>
<div class="extract">
<p>[[+extract]]</p>
</div>
</div>
Snippet Call
[[!SimpleSearch?
&perPage=`10`
&postHooks=`agendaSearch`
&facetLimit=`5`
&tpl=`CustomSearchResult`
]]