Posts

Most Recent

Data source and children content resolver

Image
If you worked on a Sitecore JSS implementation you must be familiar with the Rendering Content Resolvers used by the Layout Service to serialize the contents of a rendering data source into JSON. Out of the box, Sitecore comes with the following Rendering Content Resolvers Datasource Resolver    The default resolver which serializes the data source item Datasource Item Children Resolver   Serializes the datasource item's children Context Item Resolver Serializes the context item instead of the data source item Context Item Children Resolver  Similar to Datasource Item Children Resolver but serializes the children of the context item Folder Filter Resolver Serializes not just direct children but also the descendants of the data source item, excluding folders As you can see, there is no out of the box contents resolver that can serialize both the data source item and its children. This will be handy when you have a module that contains a parent data source item and children items cr

Referencing local data sources using ID instead of path

Image
In my previous blog post  we discussed about the problem with renaming local data sources and the issue with converting data sources created in a hierarchical structure to IDs using the out of the box PowerShell script. In this post I am going to show how to prevent using path to reference local data sources in the first place. Sitecore decides on whether to use ID or path to link data source to the rendering in presentation details at the time of selection of data source using the Select Associated Content dialog. So, I decided to take a look into what's happening behind the scenes when you click OK on this dialog using the network traffic monitor in the browser developer tools. I noticed a call to the following URL with the below response. https://demo.dev.local/sitecore/shell/default.aspx?xmlcontrol=Sitecore.Shell.Applications.Dialogs.SelectRenderingDatasource&... The response has a command called SetDialogValue with the path of local data source as value. The same call ha

Fix for the issue with renaming local data sources resulting in broken links

Image
Sitecore introduced local/page data sources with SXA. The local data sources allow better organisation of your page specific and shared data sources. However, one challenge with local data sources is, the links to them won't automatically get updated when you rename them. This is because Sitecore uses the path instead of ID to link to local data sources. If you inspect the raw value of final renderings field of a page with module that has local data source you can see the path "local:/Data/...". For this reason Sitecore warns about renaming local data sources manually. The documentation clearly says you need to convert your local data source paths to IDs using the out of the box scripts provided before renaming the local data source item. (Source: https://doc.sitecore.com/xp/en/developers/sxa/93/sitecore-experience-accelerator/data-sources.html#rename-local-data-sources) The script works fine in most cases, except for when not all your data sources are direct children of

Using Sitecore FXM to update and track contacts

Image
Sitecore Federated Experience Manager aka FXM is a great feature to utilize some of the Sitecore's CMS, marketing and analytics capabilities on non-Sitecore websites. If you are new to FXM you can read more about how to integrate FXM into your non-Sitecore website and utilize its capabilities on  Sitecore's FXM documentation page . While the well-known uses of FXM are to add placeholders to pages to show Sitecore content, track click action, assign marketing attributes and track goals, the area FXM lacks out of the box is contact tracking and updates. The FXM's scbeacon JavaScript API has following three methods you can use trackEvent trackGoal trackOutcome You can read more about these methods in the documentation . As you can see there is no out of the box API method to identify or update contact. In cases where you have a non-authenticated public website on Sitecore but an authenticated member portal on non-Sitecore website it would be really useful to pass the authentic

Sitecore Content Search API - Random Search Results using Solr

More often than you think you may get a requirement to show random related content on a page, whether it's related news articles for news website or related sale items for an eCommerce website or friend suggestions for a social networking website. This is a common requirement in eCommerce where we want to cross sell items from the same category as the current item. Most of the RDBMS databases have this feature built-in to return a random results for a select query, however Sitecore uses search providers to get its results which makes this little tricky to achieve. In this article I will show how to achieve this using the Sitecore's default search provider Solr . Solr comes with a RandomSortField out of the box which you can use to sort results randomly. You will need to pass random_{RandomValue}  or  {RandomValue}_ random  as value for sort parameter to get your search results sorted randomly. However, for the same sort value the results are always sorted in the same order. So

SXA Scriban extension to get link field target URL

Scriban is the new templating language which was introduced in Sitecore 9.3, it replaces the obsolete NVelocity templates in the earlier versions. If you are upgrading from earlier versions of Sitecore and used a lot of NVelocity templates, you need to convert all your NVelocity templates to Scriban as NVelocity is no longer supported in Sitecore 9.3. Scriban is a powerful language with support to import your own .Net functions. Sitecore provides a rich set of Scriban extensions to use which meets most of the common requirements. You can find more about the out of the box Sitecore Scriban extensions here . While using Scriban to create custom markup which can't be achieved through other Rendering Variant fields I came across a requirement to wrap a section of HTML with an anchor tag targeting to an URL set in a link field in the template. In SXA we would set the link target field on the Rendering Variant and set the Is Link property value of the Rendering Variant field to W

How to use HTML helper to render a SXA component in Razor view

Image
If you are migrating from traditional Sitecore to SXA, you may find part of your traditional component markup can be replaced with out of the box SXA component. Or if you are already using SXA you may find a need to reuse a SXA component or its Rendering Variant inside of your custom component's view. In my case, after building a custom Search Results component I realized that I can reuse one of the custom Rendering Variants I created for a Bootstrap Card markup to render search result item of my custom component. It allowed me to reuse the markup I created using Rendering Variant there by eliminating duplication of code. To render a component in your Razor view you can use the @Html.Sitecore().Rendering(path or id) helper. This works fine for rendering traditional Sitecore components. However, this helper was not built to accept the parameters required for SXA components, for e.g. the rendering variant name or id. I couldn't find any documentation on doc.sitecore.com o