Hi everyone
I'm trying to create a search page on my Power Pages site and am finding it a bit of a struggle. Ideally I wanted to add a search box to my home page so users could search for records stored in a Dataverse table added to the site. So far though I've only found that enabling search in the site settings displays a search icon on the top of every page in my site.
However, when I try clicking this icon I get the following error:
Does anyone know what could be causing this? I restarted the portal after enabling search in site settings but this hasn't helped.
Thanks in advance for your help.
Solved! Go to Solution.
Hi, I think the search template is included only on certain type of portal
You can try creating the search template using the code below and see if it will work, this is the OOB search template that comes from customer service type portal
{% assign search_enabled = settings['search/enabled'] | boolean | default:true %}
{% assign search_page = sitemarkers['Search'] %}
{% if search_enabled and search_page %}
{% assign search_filters = settings['search/filters'] | search_filter_options %}
<form method="GET" action="{{ search_page.url | h }}" role="search" class="form-search">
<div class="input-group">
{% if search_filters %}
{% assign defaultSearchFilterText = snippets["Search/Default/FilterText"] | default: resx["All"] | h %}
{% assign searchFilterLabel = snippets["Header/Search/FilterLabel"] | default: resx["Search_Filter"] | h %}
{% assign formId = uniqueid.new_guid %}
<div class="btn-group btn-select input-group-btn" data-target="#filter-{{ formId }}" data-focus="#{{search_id}}">
<li class="dropdown-submenu dropdown">
<button id="search-filter" type="button" class="btn btn-default"
data-toggle="dropdown"
aria-haspopup="true" aria-label="{{ searchFilterLabel }}" aria-expanded="false">
<span class="selected">{{ defaultSearchFilterText }}</span>
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="listbox" aria-label="{{ searchFilterLabel }}">
<li role="presentation">
<a href="#" role="option" data-value=""
aria-label="{{ defaultSearchFilterText }}" aria-selected="false" tabIndex="-1">{{ defaultSearchFilterText }}</a>
</li>
{% for search_filter_option in search_filters %}
<li role="presentation">
<a href="#" role="option" data-value="{{ search_filter_option.value | h }}"
aria-label="{{ search_filter_option.display_name | h }}" aria-selected="false" tabIndex="-1">{{ search_filter_option.display_name | h }}</a>
</li>
{% endfor %}
</ul>
</li>
</div>
<label for="filter-{{ formId }}" class="sr-only">{{ searchFilterLabel }}</label>
<select id="filter-{{ formId }}" name="logicalNames" class="btn-select" aria-hidden="true" data-query="logicalNames">
<option value="" selected="selected">{{ defaultSearchFilterText }}</option>
{% for search_filter_option in search_filters %}
<option value="{{ search_filter_option.value | h }}">{{ search_filter_option.display_name | h }}</option>
{% endfor %}
</select>
{% endif %}
<label for="{{search_id}}" class="sr-only">
{{ snippets["Header/Search/Label"] | default: resx["Search_DefaultText"] | h }}
</label>
<input type="text" class="form-control" id="{{search_id}}" name="q"
placeholder="{{ snippets["Header/Search/Label"] | default: resx["Search_DefaultText"] | h }}"
value="{{ params.q | url_encode }}"
title="{{ snippets["Header/Search/Label"] | default: resx["Search_DefaultText"] | h }}">
<div class="input-group-btn">
<button type="submit" class="btn btn-primary"
title="{{ snippets["Header/Search/ToolTip"] | default: resx["Search_DefaultText"] | h }}"
aria-label="{{ snippets["Header/Search/ToolTip"] | default: resx["Search_DefaultText"] | h }}">
<span class="fa fa-search" aria-hidden="true"></span>
</button>
</div>
</div>
</form>
{% endif %}
Can you check via Portal Management app if you have the Search Web Template?
Power Pages Super User | MVP
@OliverRodrigues thanks for the reply. I've just checked and there's no Search web template showing up in the portal management:
I'm just not sure how I go about adding it. Apologies, but I've only just started using Portals/Power Pages so still getting to grips with it all
Hi, I think the search template is included only on certain type of portal
You can try creating the search template using the code below and see if it will work, this is the OOB search template that comes from customer service type portal
{% assign search_enabled = settings['search/enabled'] | boolean | default:true %}
{% assign search_page = sitemarkers['Search'] %}
{% if search_enabled and search_page %}
{% assign search_filters = settings['search/filters'] | search_filter_options %}
<form method="GET" action="{{ search_page.url | h }}" role="search" class="form-search">
<div class="input-group">
{% if search_filters %}
{% assign defaultSearchFilterText = snippets["Search/Default/FilterText"] | default: resx["All"] | h %}
{% assign searchFilterLabel = snippets["Header/Search/FilterLabel"] | default: resx["Search_Filter"] | h %}
{% assign formId = uniqueid.new_guid %}
<div class="btn-group btn-select input-group-btn" data-target="#filter-{{ formId }}" data-focus="#{{search_id}}">
<li class="dropdown-submenu dropdown">
<button id="search-filter" type="button" class="btn btn-default"
data-toggle="dropdown"
aria-haspopup="true" aria-label="{{ searchFilterLabel }}" aria-expanded="false">
<span class="selected">{{ defaultSearchFilterText }}</span>
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="listbox" aria-label="{{ searchFilterLabel }}">
<li role="presentation">
<a href="#" role="option" data-value=""
aria-label="{{ defaultSearchFilterText }}" aria-selected="false" tabIndex="-1">{{ defaultSearchFilterText }}</a>
</li>
{% for search_filter_option in search_filters %}
<li role="presentation">
<a href="#" role="option" data-value="{{ search_filter_option.value | h }}"
aria-label="{{ search_filter_option.display_name | h }}" aria-selected="false" tabIndex="-1">{{ search_filter_option.display_name | h }}</a>
</li>
{% endfor %}
</ul>
</li>
</div>
<label for="filter-{{ formId }}" class="sr-only">{{ searchFilterLabel }}</label>
<select id="filter-{{ formId }}" name="logicalNames" class="btn-select" aria-hidden="true" data-query="logicalNames">
<option value="" selected="selected">{{ defaultSearchFilterText }}</option>
{% for search_filter_option in search_filters %}
<option value="{{ search_filter_option.value | h }}">{{ search_filter_option.display_name | h }}</option>
{% endfor %}
</select>
{% endif %}
<label for="{{search_id}}" class="sr-only">
{{ snippets["Header/Search/Label"] | default: resx["Search_DefaultText"] | h }}
</label>
<input type="text" class="form-control" id="{{search_id}}" name="q"
placeholder="{{ snippets["Header/Search/Label"] | default: resx["Search_DefaultText"] | h }}"
value="{{ params.q | url_encode }}"
title="{{ snippets["Header/Search/Label"] | default: resx["Search_DefaultText"] | h }}">
<div class="input-group-btn">
<button type="submit" class="btn btn-primary"
title="{{ snippets["Header/Search/ToolTip"] | default: resx["Search_DefaultText"] | h }}"
aria-label="{{ snippets["Header/Search/ToolTip"] | default: resx["Search_DefaultText"] | h }}">
<span class="fa fa-search" aria-hidden="true"></span>
</button>
</div>
</div>
</form>
{% endif %}
hi @mbhatt I feel like your question is more Canvas Apps related, you can post your question on this forum: Building Power Apps - Power Platform Community (microsoft.com)
Power Pages Super User | MVP