Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Form Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Customize search to omit assets folder

Go to End

4 Posts   1003 Views


Community Member, 10 Posts

17 January 2012 at 6:53am


I would like my search results to not show anything from the "assets" folder. How can I keep that folder out of the search results.

Here's my file:
<div class="viewport results-page">
<div class="content clearfix" style="padding:40px;">
<h1>Search Results</h1>
<% if Results %>
<ul id="SearchResults">
<% control Results %>
<% if MenuTitle %>
<h3><a class="searchResultHeader" href="$Link">$MenuTitle</a></h3>
<% else %>
<h3><a class="searchResultHeader" href="$Link">$Title</a></h3>
<% end_if %>
<% if Content %>
<% end_if %>
<a class="readMoreLink" href="$Link" title="Read more about &quot;{$Title}&quot;">Read more about &quot;{$Title}&quot;...</a>
<% end_control %>
<% else %>
<p>Sorry, your search query did not return any results.</p>
<% end_if %>

<% if Results.MoreThanOnePage %>
<div id="PageNumbers">
<% if Results.NotLastPage %>
<a class="next" href="$Results.NextLink" title="View the next page">Next</a>
<% end_if %>
<% if Results.NotFirstPage %>
<a class="prev" href="$Results.PrevLink" title="View the previous page">Prev</a>
<% end_if %>
<% control Results.SummaryPagination(5) %>
<% if CurrentBool %>
<% else %>
<a href="$Link" title="View page number $PageNum">$PageNum</a>
<% end_if %>
<% end_control %>

<% end_if %>

Thank You,


Community Member, 24 Posts

18 January 2012 at 3:27am

function results($data, $form, $request) {
$form->classesToSearch(array('Page', 'SiteTree'));
$data = array(
'Results' => $form->getResults(),
'Query' => $form->getSearchQuery(),
'Title' => _t('SearchForm.SearchResults', 'Search Results')
return $this->owner->customise($data)->renderWith(array('Page_results', 'Page'));

Above is my overloaded "results" method.

You can set the classesToSearch on your form in your form action. The above will only search in the Page and SiteTree tables.

Hope that helps.


Community Member, 24 Posts

15 February 2012 at 9:57am

Thanks swaiba, that's a better solution.