...
Info |
---|
Configured Hawksearch widgets - Kentico: Working with widgets |
Extending the templates
In order to override the default view file the Hawksearch search box widget uses you need to create a razor view file in your
...
frontend project at Views/Shared/Components/SearchBox/Default.cshtml.
In order to add additional templates, create corresponding view files under Views/Shared/Components/SearchBox/ .
When displayed in the widget settings, they will be split by capital letters and words after the first will be lowercased. So a view file called βSearchBoxTemplateOneβ will be displayed like βSearch box template oneβ in the widget settings.
The way the connector is designed it will automatically find the razor view files in that folder and use them. Below is the Default.cshtml code used for each NuGet version.
Kentico 12 NuGet
Code Block |
---|
@model Hawksearch.Kentico.Xperience.UI.Widgets.SearchBoxViewModel @{ var trackedEvents = new List<string>() { Model.Properties.TrackAutocompleteClickEvent ? "AutocompleteClick" : "", Model.Properties.TrackSearchEvent ? "Search" : "" }; var eventsJson = Newtonsoft.Json.JsonConvert.SerializeObject(trackedEvents.Where(a => !string.IsNullOrEmpty(a))); var settingsJson = Newtonsoft.Json.JsonConvert.SerializeObject(Model.ConnectorSettings); var language = Model.ConnectorSettings.MultilingualIndexingEnabled ? CMS.Localization.LocalizationContext.CurrentCulture.CultureCode : ""; } @if (Model.ConnectorSettings.FrontendFramework == Hawksearch.Kentico.Xperience.CMS.Configuration.FrontendFrameworkType.Vue) { <div class="vue-app-wrapper-ae" data-indexname="@Model.Properties.IndexName" data-language="@language" data-trackedevents="@eventsJson" data-hawksearchsettings="@settingsJson"> <div class="hawk"> <div class="hawk__header"> @if (string.IsNullOrWhiteSpace(Model.SearchPageUrl)) { <search-box></search-box> } else { <search-box search-page="@Model.SearchPageUrl"></search-box> } </div> </div> </div> } else { <div id="hawksearch-react-search-box" data-indexname="@Model.Properties.IndexName" data-language="@language" data-trackedevents="@eventsJson" data-hawksearchsettings="@settingsJson" data-searchpageurl="@Model.SearchPageUrl"> </div> } |
Kentico 13 NuGet
Code Block |
---|
@model Hawksearch.Kentico.Xperience.UI.Widgets.SearchBoxViewModel @{ var trackedEvents = new List<string>() { Model.ComponentViewModel.Properties.TrackAutocompleteClickEvent ? "AutocompleteClick" : "", Model.ComponentViewModel.Properties.TrackSearchEvent ? "Search" : "" }; var eventsJson = Newtonsoft.Json.JsonConvert.SerializeObject(trackedEvents.Where(a => !string.IsNullOrEmpty(a))); var settingsJson = Newtonsoft.Json.JsonConvert.SerializeObject(Model.ConnectorSettings); var language = Model.ConnectorSettings.MultilingualIndexingEnabled ? CMS.Localization.LocalizationContext.CurrentCulture.CultureCode : ""; } @if (Model.ConnectorSettings.FrontendFramework == Hawksearch.Kentico.Xperience.CMS.Configuration.FrontendFrameworkType.Vue) { <div class="vue-app-wrapper-ae" data-indexname="@Model.ComponentViewModel.Properties.IndexName" data-language="@language" data-trackedevents="@eventsJson" data-hawksearchsettings="@settingsJson"> <div class="hawk"> <div class="hawk__header"> @if (string.IsNullOrWhiteSpace(Model.SearchPageUrl)) { <search-box></search-box> } else { <search-box search-page="@Model.SearchPageUrl"></search-box> } </div> </div> </div> } else { <div id="hawksearch-react-search-box" data-indexname="@Model.ComponentViewModel.Properties.IndexName" data-language="@language" data-trackedevents="@eventsJson" data-hawksearchsettings="@settingsJson" data-searchpageurl="@Model.SearchPageUrl"> </div> } |
...