Jump to:

1999 Posts in 1408 Topics by 613 members

Form Questions

SilverStripe Forums » Form Questions » Customize search to omit assets folder

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

Page: 1
Go to End
Author Topic: 565 Views
  • webmmsd
    Avatar
    Community Member
    10 Posts

    Customize search to omit assets folder Link to this post

    Hello,

    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 page_results.ss file:
    <div class="viewport results-page">
       <div class="content clearfix" style="padding:40px;">
       <h1>Search Results</h1>
       <% if Results %>
        <ul id="SearchResults">
        <% control Results %>
        <li>
        <% 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 %>
           $Content.FirstParagraph(NoHTML)
              <% end_if %>
        <a class="readMoreLink" href="$Link" title="Read more about &quot;{$Title}&quot;">Read more about &quot;{$Title}&quot;...</a>
        </li>
        <% end_control %>
        </ul>
        <% 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 %>
        <span>
        <% control Results.SummaryPagination(5) %>
        <% if CurrentBool %>
        $PageNum
        <% else %>
        <a href="$Link" title="View page number $PageNum">$PageNum</a>
        <% end_if %>
        <% end_control %>
        </span>

        </div>
        <% end_if %>
       </div>
    </div>

    Thank You,
    Alex

  • SamTheJarvis
    Avatar
    Community Member
    24 Posts

    Re: Customize search to omit assets folder Link to this post

    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.

  • swaiba
    Avatar
    Forum Moderator
    1784 Posts
  • SamTheJarvis
    Avatar
    Community Member
    24 Posts

    Re: Customize search to omit assets folder Link to this post

    Thanks swaiba, that's a better solution.

    565 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.