Posts

Showing posts from February, 2020

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

Inline thank you message in Sitecore Forms

Image
With the release of Sitecore XP 9.3 a lot of modules that were previously part of Sitecore Forms Extensions now come out of the box, which is great. The new features like automatic bot detection, file upload field and option to publish from the Forms Editor makes life easy. However, one thing that kept bothering me is the lack of option to show an inline thank you/success message on the form without having to move to the next page within the form or redirect to a whole new page. This seems to have been asked in forums multiple times and there are a couple of hacks to achieve this. But I couldn't find any of them clean or easily maintainable in the long run. So, I decided to take the matters into my own hands. Here are few simple steps to achieve this... Step 1 Create a custom pipeline processor for forms.renderForm pipeline. We want to show a thank you message only on submit button click (not on first load) and only when the form is submitted successfully. We can find if t