0

I have a general link that is linking to an item in Sitecore.
Path to linked item --> /sitecore/content/home/pageItemWithLayout

I am using the below scriban script below to render the item link.

<a href = "{{i_item.Link.Target}}"  target="_blank">Some item Link </a>      
                                                                                                 

and HTML is rendered

<a href="/sitecore/content/home/pageItemWithLayout" target="_blank">Some item Link </a>

is there a way to access a friendly URL for this Sitecore item in scriban similar to how we can use Sitecore LinkManager Sitecore.Links.LinkManager.GetItemUrl(itempath) to get the friendly url?

The output required after scriban render is

<a href="/pageItemWithLayout" target="_blank">Some item Link </a>

This item could also be present in a microsite as well.

2 Answers 2

1

You can use field renderer like:

{{ sc_field i_item 'Link' [['target', '_blank']] }}
3
  • is there a way to make this link uneditable in experience editor?
    – Shaurya
    Commented Feb 11, 2022 at 14:16
  • I don't think that's possible. But you can always try to write you own scriban function, see examples here sitecorenutsbolts.net/2020/05/13/Rendering-Links-with-Scriban
    – Marek Musielak
    Commented Feb 11, 2022 at 14:40
  • Thanks @Marek. we ended up writing our own scriban function to achieve this.
    – Shaurya
    Commented Feb 16, 2022 at 11:34
1

You can use the field render option as Marek described and you can also use sc_link as described here: https://doc.sitecore.com/xp/en/developers/sxa/102/sitecore-experience-accelerator/the-embedded-functions-for-the-scriban-template.html

Your code would be:

<a href = "{{sc_link i_item.Link.Target}}"  target="_blank">Some item Link </a> 

Your Answer

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

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