0

I have created a variant to list down data source items using result variant selector and all these data items will need to point to wildcard content item .How to form URL of wildcard item in Scriban?

3
  • 1
    Wouldn't it be a good idea to have a linkprovider handle this for you (and use the ootb link methods in Scriban)? This way all your links to those items will be consistent.
    – Gatogordo
    Mar 16, 2022 at 10:43
  • how OOTB scriban link methods work with wildcard item? Mar 16, 2022 at 11:38
  • If you fetch the url of an item, the Scriban extension will use the linkprovider (note: this is an assumption, didn't test this but would seem rather silly if it didn't). So you should get the data item and request the link. And let the linkprovider handle the logic. The logic in the linkprovider should generate the correct link towards the wildcard (instead of the dataitem).
    – Gatogordo
    Mar 16, 2022 at 13:21

1 Answer 1

1

Step 1: get your link correctly

To make sure the links to a wildcard item are consistent in the whole site, you should tell Sitecore how you want the links to be created. This used to be creating your own LinkProvider. SXA already has it's own linkprovider - it is documented here how to add a custom one. Short version:

<linkManager defaultProvider="switchableLinkProvider">
<providers>
<add name="customLinkProvider" type="Sitecore.XA.Foundation.Multisite.LinkManagers.LocalizableLinkProvider, Sitecore.XA.Foundation.Multisite" cacheExpiration="5" addAspxExtension="false" alwaysIncludeServerUrl="false" encodeNames="true" languageEmbedding="always" languageLocation="filePath" shortenUrls="true" useDisplayName="false"/>
</providers>
</linkManager>

And add your linkprovider name in the SXA site definition item.

It did also find this article though: https://www.konabos.com/blog/sitecore-linkprovider-is-now-obsolete This mentions a new way of creating custom linkprovider code. I didn't test this and I'm not sure if this is also the case in a SXA environment so you will have to check this yourself.

In this link providing code you need to check whether the item is one of your data items and if so create the url towards the wildcard item as you please.

To test if a correct url is generated, just link to (one of) your data items in a RichText field and let Sitecore generate the urls.

Step 2: use it in Scriban

If you request the link to an item in Scriban, it will use the Sitecore api and that means the linkprovider will be used as well. So if step 1 was completed successfully, this should work fine.

So you'll need sc_link (with the data item as argument) or data_item.url.

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.