Search Results Widget Template Reference

While creating a search results widget template, you can access pre-populated variables in the FreeMarker template editor. The variables listed in the editor hint at what’s possible, but there are many more variables available in the search results widget template context. The source code specific to your version contains the authoritative list of variables that are injected into the template context.

These Java classes provide the available template variables for the Search Results widget. You can find them by searching https://github.com/liferay/liferay-portal/tree/7.4.3.112-ga112:

  • SearchContainer: Some of the getters in this class are variables in the search results widget template. See the list below for what’s available.
  • SearchResultsPortletDisplayContext: All the getters in this class provide variables to the search results widget template (e.g., getDisplayStyleGroupId()).
  • SearchResultSummaryDisplayContext: All the getters in this class provide variables to the search results widget template (e.g., getDisplayStyleGroupId()).

Here is an easier to digest list of the currently available variables:

Editor Field NameDescriptionJava Return TypeUsage Example
DocumentsThe collection of the search result entries. To see what’s available for each entry, see the Search Result Entry Fields.List< SearchResultSummaryDisplayContext>
Search ContainerYou can use the search container to build a grid with search results and their properties.SearchContainerSee Using the Search Container for an example.
The current results page numberint${searchContainer.getCur()}
The current page number’s parameter nameString${searchContainer.getCurParam()}
The delta, or number of entries to display per pageint${searchContainer.getDelta()}
The delta parameter nameString${searchContainer.getDeltaParam()}
The index of the last result to showint${searchContainer.getEnd()}
An ID for the search container instanceString${searchContainer.getId(request, nameSpace)}
The page URL for paginationPortletURL${searchContainer.getIteratorURL()}
Sort columnString${searchContainer.getOrderByCol()}
Sort column parameter nameString${searchContainer.getOrderByColParam() }
An order type for the columns, either ascending or descendingString${searchContainer.getOrderByType()}
The parameter to order byString${searchContainer.getOrderByTypeParam()}
The Portlet requestPortletRequest${searchContainer.getPortletRequest()}
The index of the last hit to showint${searchContainer.getResultEnd()}
The list of result documentsList<Document>${searchContainer.getResults()}
The number of hits to skip from the beginningint${searchContainer.getStart()}
The total number of hitsint${searchContainer.getTotal()}
Whether there are any resultsboolean${searchContainer.hasResults()}
Whether the user can choose the number of items displayed per pageboolean${searchContainer.isDeltaConfigurable()}
Whether to use hover effectsboolean${searchContainer.isHover()}
Search Results Display ContextInformation about the current search and widget configurationSearchResultsDisplayContext
The widget template’s site IDlong${searchResultsPortletDisplayContext.getDisplayStyleGroupId()}
The retrieved search engine documentsList<Document>${searchResultsPortletDisplayContext.getDocuments()}
The current search keywordsString${searchResultsPortletDisplayContext.getKeywords()}
The search containerSearchContainer${searchResultsPortletDisplayContext.getSearchContainer()}
The search results portlet instance configurationSearchResultsPortletInstanceConfiguration${searchResultsPortletDisplayContext.getSearchResultsPortletInstanceConfiguration()}
The search result summary context for the search engine document. See Search Result Entry Fields.SearchResultSummaryDisplayContext${searchResultsPortletDisplayContext.getSearchResultSummaryDisplayContext(document)}
The search result summary contexts. See Search Result Entry Fields.List<SearchResultSummaryDisplayContext>${searchResultsPortletDisplayContext.getSearchResultSummaryDisplayContexts()}
The total number of hitsint${searchResultsPortletDisplayContext.getTotalHits()}
Whether the widget is visibleboolean${searchResultsPortletDisplayContext.isRenderNothing()}
Whether the widget configuration enables showing an empty results messageboolean${searchResultsPortletDisplayContext.isShowEmptyResultMessage()}
Whether the configuration enables paginationboolean${searchResultsPortletDisplayContext.isShowPagination()}

There are variables you can use for each search result. Some appear in the template editor, but there are more:

Editor Field NameDescriptionTypeUsage Example
The asset’s user ID. If the entry is a user, the value is that user’s ID.long${entry.getAssetEntryUserId()}
The asset’s download URLString${entry.getAssetRendererURLDownload()}
The entry’s model class nameString${entry.getClassName()}
The primary key of the entry’s backing modellong${entry.getClassPK()}
ContentThe highlighted search result summary contentString${entry.getContent()}
Creation DateThe entry creation dateString${entry.getCreationDateString()}
Created by User NameThe full name of the entry creatorString${entry.getCreatorUserName()}
Created by User PortraitThe URL to the entry creator’s portrait/avatarString${entry.getCreatorUserPortraitURLString()}
The asset category ID request parameter nameString${entry.getFieldAssetCategoryIds()}
The asset tag name request parameter nameString${entry.getFieldAssetTagNames()}
TitleThe highlighted titleString${entry.getHighlightedTitle()}
The CSS icon class for the represented model class/asset entry typeString${entry.getIconId()}
The summary language ID, if different from the current display languageString${entry.getLocaleLanguageId()}
A notification text that the summary language ID is different from the current display languageString${entry.getLocaleReminder()}
The label for the model class represented by the entryString${entry.getModelResource()}
Modified by User NameThe full name of the entry’s last modifierString${entry.getModifiedByUserName()}
Modified by User PortraitThe URL to the last modifier’s portrait/avatarString${entry.getModifiedByUserPortraitURLString()}
Modified DateThe entry’s last modification dateString${entry.getModifiedDateString()}
The path of the current theme’s image directoryString${entry.getPathThemeImages()}
The portlet URL for the search results portlet instancePortletURL${entry.getPortletURL()}
Publish DateThe entry’s publication dateString${entry.getPublishedDateString()}
The URL to a thumbnail for the backing asset entryString${entry.getThumbnailURLString()}
The title for the search result entry’s backing assetString${entry.getTitle()}
The URL to the portrait/avatar of the user who created the backing asset entryString${entry.getUserPortraitURLString()}
The view URL for the search result entryString${entry.getViewURL()}
Whether the backing asset entry has asset categories or tagsboolean${entry.isAssetCategoriesOrTagsVisible()}
Whether the asset’s download URL is availableboolean${entry.isAssetRendererURLDownloadVisible()}
Whether the summary content is availableboolean${entry.isContentVisible()}
Whether the creation date is availableboolean${entry.isCreationDateVisible()}
Whether the creator’s portrait is availableboolean${entry.isCreatorUserPortraitVisible()}
Whether the creator’s name is availableboolean${entry.isCreatorVisible()}
Whether the document display mode is enabledboolean${entry.isDocumentFormVisible()}
Whether the document fields for entries without class name or primary key are availableboolean${entry.isFieldsVisible()}
Whether the CSS icon class for the represented model class/asset entry type is availableboolean${entry.isIconVisible()}
Whether the locale reminder text is availableboolean${entry.isLocaleReminderVisible()}
Whether the label for the model class represented by this entry is availableboolean${entry.isModelResourceVisible()}
Whether the last modifier’s name is availableboolean${entry.isModifiedByUserNameVisible()}
Whether the last modifier’s portrait is availableboolean${entry.isModifiedByUserPortraitVisible()}
Whether the last modification date is availableboolean${entry.isModifiedDateVisible()}
Whether the published date is availableboolean${entry.isPublishedDateVisible()}
Whether the entry is unavailable because of an errorboolean${entry.isTemporarilyUnavailable()}
Whether a thumbnail is available for the assetboolean${entry.isThumbnailVisible()}
Whether the portrait is available for the asset entry creatorboolean${entry.isUserPortraitVisible()}

Using the Search Container

Here’s an example of setting up the search container to show your search results:

<@liferay_ui["search-container"] searchContainer=searchContainer>

   <@liferay_ui["search-container-results"] results=searchContainer.results>

      <@liferay_ui["search-container-row"]
         className="com.liferay.portal.kernel.search.Document"
         keyProperty="UID" modelVar="document"
      >

         <@liferay_ui["search-container-column-text"]
            href="" name="Title" value=document.get("localized_title_en_US")
         />
      </@>
   </@>

   <@liferay_ui["search-iterator"] />
</@>
<#assign localized_title_field="localized_title_${locale}"/>
<#assign localized_content_field="content_${locale}"/>

<@liferay_ui["search-container"] searchContainer=searchContainer>

   <@liferay_ui["search-container-results"] results=searchContainer.results>

      <@liferay_ui["search-container-row"]
         className="com.liferay.portal.kernel.search.Document"
         keyProperty="UID" modelVar="document"
      >
				<@liferay_ui["search-container-column-text"]
               href="" name="Title" value=document.get(localized_title_field)
            />

				<@liferay_ui["search-container-column-text"]
               href="" name="Content" value=document.get(localized_content_field)
            />

				<@liferay_ui["search-container-column-text"]
               href="" name="Class Name" value=document.get("entryClassName")
            />
      </@>
   </@>

   <@liferay_ui["search-iterator"] />
</@>

The search container shows a grid of search results.

Capabilities

Product

Contact Us

Connect

Powered by Liferay
© 2024 Liferay Inc. All Rights Reserved • Privacy Policy