Sitecore Experience Accelerator (SXA) Rendering Variants: Wrap Link Field Around Another Field | Perficient Digital

Sitecore Experience Accelerator (SXA) Rendering Variants: Wrap Link Field Around Another Field

As we covered in the first post on the basics of Rendering Variants in SXA, Rendering Variants are configurable adaptations of default renderings. With Sitecore Experience Accelerator (SXA), we can display many variations of a Component using Rendering Variants. In this blog post, we will look at the scenario where we want to wrap a link coming from a General Field around the content of a Rich Text field.

For this example, we will be using SXA’s Page Content Component. I have added the following fields to my Page Template, which I will use in our Rendering Variants to demonstrate how we can wrap a link from one field around another.

I have the following fields in my Page item:

  1. Page Title (Rich Text)
  2. Content (Rich Text)
  3. CTA Link (General Link)
  4. Wrapper Link (General Link)

Below, I populated all the fields as shown in the image:

field population


Now, go to the /sitecore/content/Main/Website/Presentation/Rendering Variants/Page Content and add a Variant Definition item named “Link Wrapped Content.

Now, in our Link Wrapped Content fill the “Field used as Link target” field with our Wrapper Link field name link on the following image.


Link Wrapped Content


Then, right-click on the Link Wrapped Content item and insert three Field type items named Page Title, Content, and CTA Link.

Field type items


Next, click on the item Named Content under our Variant Definition and check “Is Link” checkbox. “Is Link” checkbox will make sure that this field is rendered inside the Link element that we provided earlier in our Variant Definition’s “Field used as Link target” field.

Other fields which do not have “Is Link” checkbox checked will be rendered outside normally.


Is Link checkbox


We are now done creating our Rendering Variant.

Time to Test It!

Go to the Experience Editor and drop SXA’s Page Content component on the page. From the Variant dropdown, select our Variant Definition Link Wrapped Content. Here’s the resulting view of our Variant of Page Content Component.


Variant of Page Content Component


From the HTML structure from the below image, you can see that the content field is rendered inside a link element that has the URL of Wrapper Link field.


Wrapper link field


In the above post, we learned how to make a Rendering Variant that will render the content of a Rich text field inside as a Wrapper Link coming from another general link field. In the next part of this series, we will discuss using custom tokens in Rendering Variants.

Leave a Reply