Skip to main content

Posts

Adding Custom Classes in body tag of page in Sitecore SXA

Recent posts

Custom field validation rule for date range in Sitecore

 Hello learners, Welcome to Learn Sitecore. In this blog we will see how to create custom field validation rule for a field of an item. Providing a field validation rule to a field provides a great flexibility to the developers as well as good experience for content authors. By adding it choosing an invalid date by content author and showing it in the website can be eliminated at the first step itself. It is recommended to use field validations for different fields based on the business requirements. To implement a custom field rule validation, navigate to  /sitecore/system/Settings/Validation Rules/Field Rules and insert a validation rule. After that fill the data into Text and Data sections as follows. Text Section Data Section In the Type field add the data as class reference name, assembly name. Now create a class file that extends the standard validator class. Write the logic as per your requirement in the Evaluate function. For the instance I have added a sample code wh...

Filter search results by date range in Sitecore SXA Search

Hey blog viewers, Welcome to Learn Sitecore.  Sitecore SXA OOTB Search module contains many OOTB features such as search results, sort results and different filter types etc... To render the search results in a page, Search results rendering from OOTB will help. It contains the following details for the component display. Data Source : The data source template contains a single line text field. The content given in this field will be used to render when the search results are zero for specified scope. Rendering Parameter fields : In the rendering parameter fields we need to choose the following for the search component to work.  Search Signature : This field will help to map the search results to the correct rendering. If we add only one search results rendering to a page, this field can left blank but when more than one rendering of type search results added to the same page, this field shouldn't be blank. If the field left blank for both renderings, then which ever loads fir...

Remove bucket folders from page URL

 Hey blog viewers, Welcome to Learn Sitecore.  In this blog we will see how to remove bucket folders from page URL. It is the best practice for the Sitecore application to have a clean URL to meet it's SEO purposes. So let's go through how we can achieve this.  First, in order to remove the bucket folders from the URL we have to decide the URL structure we need to keep and follow for the pages stored under bucket folder. For the instance I am taking the following URL https://developersite.com/news/2022/06/17/news-1. In this URL 2022/06/17 represents the bucket folders. This structure of bucket folders can be different based on the structure that one will follow up on the requirement. After removing the bucket folders from URL, it will be https://developersite.com/news/news-1 . In order to do this we first need to build this customized URL. For that we would need to create a new link provider which overrides the GetItemUrl method present in the link providers pro...

Sitecore Power Shell Scripts

Export dictionaries into a CSV file Here we can see how to export the dictionaries data, key and phrases, into a csv file using a power shell script.  $DataPath = "Give the path of Csv file to export dictionaries data" $allItems = Get-ChildItem -Path 'master:Give the path of dictionaries parent item' -Recurse $Results = @() ForEach ($item in $allItems) {  if($item.TemplateName -eq "Dictionary Entry")    {  $LangItem = Get-Item -Path $item.FullPath -Language "Give the language code in case of secondary language data is needed. For example nl for Dutch language     $Properties = @{  ItemName = $item.Name   Key = $item["Key"]    EnglishPhrase = $item["Phrase"]  }    if($LangItem -ne $null) {        $Properties.Add("LangPhrase", $LangItem["Phrase"])   }    $Results += New-Object psobject -Property $Properties  } } $Results | Select-Object ItemName, Key, EnglishPhrase, LangPhras...