0

I am using SXA 1.8.1 Sitecore 9.1.1.

I have a rendering variant with link wrapping a few other items (image, text etc.). I would like to pass the target attribute value which is set on the link by the editors to the variant to display something like:

<a href="something" target="_blank"> ... </a>

Is it possible to pass it through the data attributes on the link section using token or something like that? I tried using "Is Link" and without it but none of them seems to be rendering that OOTB. How can I implement it? I do not want to hardcode the _blank value (it works in this case but I need editors to be able to set it on the link item).

example

4
  • I suggest you consider an upgrade to Sitecore 9.3. You will get the ability to use Scriban templates and it will be much easier to achieve what you want.
    – Anton
    Apr 6, 2021 at 10:25
  • It is planned for the future but unfortunately because of budget restrictions I need a solution right now as well. We can use NVelocity
    – 9_9
    Apr 6, 2021 at 10:37
  • 1
    Have you specified field "Field used as link target" on rendering variant definition? If no specify it and then just check "Is Link". It should set href to url and target should be _blank of you specify link to open in New browser window Apr 6, 2021 at 11:04
  • I specified the field but it does not help much - I need to use section instead of the field because it does not pass the HTML validation otherwise. When using the section it does not pass the target value at all.
    – 9_9
    Apr 6, 2021 at 11:19

1 Answer 1

4

To achieve this you have the field "Field used as link target" in the Variant Definition item.

enter image description here

Then when you select the "wrapped" option in "Is link" field for your image variant field, it will wrap your image with the link provided in the Variant Definition

enter image description here

And this link will have the target properties. Hope it helps.

1
  • Thanks for the answer, unfortunately inside the link I have not only the image field but also another section with div and a few different properties. I don't want to select "is link" on every property. I cannot use link field and have something nested underneath it because then I get HTML validation errors. So it seems to me that the only way to do it would be by using the section and wrap everything into "a" tag. But when I do that then the link target is not going to be set correctly. Is there any other way how it could be done?
    – 9_9
    Apr 13, 2021 at 12:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.