Skip to content
Basic site search for the SilverStripe Elemental module
PHP Scheme
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

SilverStripe Elemental Site Search Module

Basic site search for the SilverStripe Elemental module. It works by saving a text reprentation of the elemental area to an extra field in SiteTree.



Install this module with composer

composer require jbennecker/silverstripe-elemental-site-search

Make sure you don't have FulltextSearchable enabled in _config.php.

Add the search form

To add the search form, add $SearchForm anywhere in your template.

For example in

<div class="search-form">

Override the template

Lastly you can overrde the template for the result page.


<div id="Content" class="searchResults">

    <% if $Query %>
        <p class="searchQuery"><strong>You searched for &quot;{$Query}&quot;</strong></p>
    <% end_if %>

    <% if $Results %>
    <ul id="SearchResults">
        <% loop $Results %>
            <a class="searchResultHeader" href="$Link">
                <% if $MenuTitle %>
                <% else %>
                <% end_if %>
            <a class="readMoreLink" href="$Link" 
                title="Read more about &quot;{$Title}&quot;"
                >Read more about &quot;{$Title}&quot;...</a>
        <% end_loop %>
    <% 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 %>
            <% loop $Results.Pages %>
                <% if $CurrentBool %>
                <% else %>
                <a href="$Link" title="View page number $PageNum">$PageNum</a>
                <% end_if %>
            <% end_loop %>
        <p>Page $Results.CurrentPage of $Results.TotalPages</p>
    <% end_if %>

Clear caches

Then finally add ?flush=1 to the URL and you should see the new template.

You can’t perform that action at this time.