Search Results Page

Overview

The Search Results page shows the results from a search. The results can be paginated. A search form can also be shown on the page to make it easy to perform a new search.

The URL for the page is constructed so that individual search results pages can be bookmarked if desired. 

Code samples

Simple

This is a simple example showing a basic search results page.

{% if totalItemCount > 0 %}
  <h3>{{ firstItemNumber }} - {{ lastItemNumber }} of {{ totalItemCount }}
  {% if totalItemCount > 1 %}
    results
  {% else %}
    result
  {% endif %}
  for "{{ searchTerm }}".
  </h3>

  {% if resultsPerPageIntervals > 0 %}
    <p>
    {% for key,interval in resultsPerPageIntervals %}
       {% if key > 0 %} | {% endif %}
       <a href="{{ interval.url }}">{{ interval.number }}</a>
    {% endfor %}
    </p>
  {% endif %}
  {% for result in results %}
      <p>
      <a href="{{ result.url }}">{{ result.title }}</a><br />
      <span>{{ result.publishDate }}</span><br />
      {% if result.content %}
        {{ result.content }}
      {% endif %}
      </p>
  {% endfor %}
  
  {% if pageCount > 1 %}
    {% if previousUrl %}
      <a href="{{ previousUrl }}" title="Previous Page">&lt; Previous</a> | 
    {% endif %}
    {% for page in pagesInRange %}
      {% if page.number != current %}
        <a href="{{ page.url }}" title="Go to Page {{ page.number }}">{{ page.number }}</a>
      {% else %}
        <strong>{{ page.number }}</strong>
      {% endif %}
    {% endfor %}
    
    {% if nextUrl %}
      | <a href="{{ nextUrl }}" title="Next Page">Next &gt;</a>
    {% endif %}
  {% endif %}

  {{ form.content }}  
{% else %}
  <p>There were no results for "{{ searchTerm }}".</p>
  <p>Search again</p>
  {{ form.content }}
{% endif %}

Simple w/ Search Segments

This is a simple example showing a basic search results page that includes the search segment hidden form fields to search the existing search segments again.

{% if totalItemCount > 0 %}
  <h3>{{ firstItemNumber }} - {{ lastItemNumber }} of {{ totalItemCount }}
  {% if totalItemCount > 1 %}
    results
  {% else %}
    result
  {% endif %}
  for "{{ searchTerm }}".
  </h3>

  {% if resultsPerPageIntervals > 0 %}
    <p>
    {% for key,interval in resultsPerPageIntervals %}
       {% if key > 0 %} | {% endif %}
       <a href="{{ interval.url }}">{{ interval.number }}</a>
    {% endfor %}
    </p>
  {% endif %}
  {% for result in results %}
      <p>
      <a href="{{ result.url }}">{{ result.title }}</a><br />
      <span>{{ result.publishDate }}</span><br />
      {% if result.content %}
        {{ result.content }}
      {% endif %}
      </p>
  {% endfor %}
  
  {% if pageCount > 1 %}
    {% if previousUrl %}
      <a href="{{ previousUrl }}" title="Previous Page">&lt; Previous</a> | 
    {% endif %}
    {% for page in pagesInRange %}
      {% if page.number != current %}
        <a href="{{ page.url }}" title="Go to Page {{ page.number }}">{{ page.number }}</a>
      {% else %}
        <strong>{{ page.number }}</strong>
      {% endif %}
    {% endfor %}
    
    {% if nextUrl %}
      | <a href="{{ nextUrl }}" title="Next Page">Next &gt;</a>
    {% endif %}
  {% endif %}

 {{ form.content }}  
{% else %}
  <p>There were no results for "{{ searchTerm }}"</p>
  <p>Search again</p>
  {{ form.content }}
{% endif %}

Using App Data to Show Icons Next to Each Result

This example uses app information for each search result to show an image next to each search result item.

{% if totalItemCount > 0 %}
  <h3>{{ firstItemNumber }} - {{ lastItemNumber }} of {{ totalItemCount }}
  {% if totalItemCount > 1 %}
    results
  {% else %}
    result
  {% endif %}
  for "{{ searchTerm }}".
  </h3>

  {% if resultsPerPageIntervals > 0 %}
    <p>
    {% for key,interval in resultsPerPageIntervals %}
       {% if key > 0 %} | {% endif %}
       <a href="{{ interval.url }}">{{ interval.number }}</a>
    {% endfor %}
    </p>
  {% endif %}
  {% for result in results %}
      <p>
      {% if result.app == 'page' %}
        <img src="/images/documentation/icons/blog_blue.png" height="16" width="16" alt="Page" />
      {% elseif result.app == 'blog' %}
        <img src="/images/documentation/icons/blog.png" height="16" width="16" alt="Blog" />
      {% elseif result.app == 'calendar' %}
        <img src="/images/documentation/icons/calendar_month.png" height="16" width="16" alt="Calendar" />
      {% elseif result.app == 'document' %}
        {% if result.appData.fileExtension %}
          {% set ext = result.appData.fileExtension %}
          {% if ext == 'doc' || ext == 'docx' %}
            <img src="/images/documentation/icons/document_word.png" height="16" width="16" alt="Word" />
          {% elseif ext == 'pdf' %}
            <img src="/images/documentation/icons/document_pdf.png" height="16" width="16" alt="PDF" />
          {% elseif ext == 'xls' || ext == 'xlsx' %}
            <img src="/images/documentation/icons/document_excel.png" height="16" width="16" alt="Excel" />
          {% elseif ext == 'ppt' || ext == 'pptx' %}
            <img src="/images/documentation/icons/document_powerpoint.png" height="16" width="16" alt="Powerpoint" />
          {% elseif ext == 'csv' %}
            <img src="/images/documentation/icons/document_excel_csv.png" height="16" width="16" alt="CSV" />
          {% else %}
            <img src="/images/documentation/icons/document.png" height="16" width="16" alt="Document" />
          {% endif %}
        {% else %}
          <img src="/images/documentation/icons/document.png" height="16" width="16" alt="Document" />
        {% endif %}
      {% elseif result.app == 'forum' %}
        <img src="/images/documentation/icons/sort.png" height="16" width="16" alt="Forum" />
      {% elseif result.app == 'news' %}
        <img src="/images/documentation/icons/newspaper.png" height="16" width="16" alt="News" />
      {% endif %}
      <a href="{{ result.url }}">{{ result.title }}</a><br />
      <span>{{ result.publishDate }}</span><br />
      {% if result.content %}
        {{ result.content }}
      {% endif %}
      </p>
  {% endfor %}
  
  {% if pageCount > 1 %}
    {% if previousUrl %}
      <a href="{{ previousUrl }}" title="Previous Page">&lt; Previous</a> | 
    {% endif %}
    {% for page in pagesInRange %}
      {% if page.number != current %}
        <a href="{{ page.url }}" title="Go to Page {{ page.number }}">{{ page.number }}</a>
      {% else %}
        <strong>{{ page.number }}</strong>
      {% endif %}
    {% endfor %}
    
    {% if nextUrl %}
      | <a href="{{ nextUrl }}" title="Next Page">Next &gt;</a>
    {% endif %}
  {% endif %}

 {{ form.content }}  
{% else %}
  <p>There were no results for "{{ searchTerm }}"</p>
  <p>Search again</p>
  {{ form.content }}
{% endif %}
This documentation is only for Aptuitiv CMS. Learn more.
Get Started With Aptuitiv