@namespace Oqtane.Themes.Controls @using System.Net @using Microsoft.AspNetCore.Http @inherits ThemeControlBase @inject ISettingService SettingService @inject IStringLocalizer Localizer @inject NavigationManager NavigationManager @if (_searchResultsPage != null) { @if (AllowInput) {
} else {
} } @code { private Page _searchResultsPage; private string _keywords = ""; [Parameter] public string CssClass { get; set; } [Parameter] public bool AllowInput { get; set; } = true; // setting to false will display only the search icon button - not the textbox [Parameter] public string SearchResultPagePath { get; set; } = "search"; // setting to "" will disable search [CascadingParameter] HttpContext HttpContext { get; set; } [SupplyParameterFromForm(FormName = "SearchForm")] public string KeyWords { get => ""; set => _keywords = value; } protected override void OnInitialized() { if (bool.Parse(SettingService.GetSetting(PageState.Site.Settings, "Search_Enabled", "True"))) { if (!string.IsNullOrEmpty(SearchResultPagePath)) { _searchResultsPage = PageState.Pages.FirstOrDefault(i => i.Path == SearchResultPagePath); } } } private void PerformSearch() { if (_searchResultsPage != null) { var url = NavigateUrl(_searchResultsPage.Path, $"q={WebUtility.UrlEncode(_keywords)}"); NavigationManager.NavigateTo(url); } } }