4

SXA comes with a linkProvider called the switchableLinkProvider. I have seen the official doc about custom link providers in SXA but I don't need a custom link provider, I just need to understand what the difference is between this and localizedProvider shipped with SXA.

1 Answer 1

11

The switchableLinkProvider in SXA is unfortunately not documented anywhere at present, but it is a very powerful mechanism.

Most URL's when rendered by Sitecore will either call the Sitecore LinkManager or they will bypass that and go direct to a specific link provider. To create a consistent experience with all links across a site, or if the solution is a multi-site solution, it is best practice to make the default link provider the switchableLinkProvider.

This is because when the LinkManager is used, it will use the default link provider. That's where the smarts come in. The switchableLinkProvider will then check the current site context of the request, and then check on the Site Grouping whether any other link provider has been defined. If so, it will use this provider, else it will use the provider defined by the XA.Foundation.Multisite.FallbackLinkProvider which is localizedProvider by default.

So if you need to make any changes to the link behaviour globally, it would be good to simply patch the localizedProvider settings. If the change needs to be site specific, then that's where you could define a custom link provider, and then update the site grouping Link provider name field as mentioned here.

Minor note:

Currently the above linked document example has this: <linkManager defaultProvider="sitecore">

This example is actually disabling the power of the switchableLinkProvider. If you need to create a custom link provider just patch in like this for example:

<linkManager>
  <providers>
    <add name="localizedProvider">
      <patch:attribute name="languageEmbedding">never</patch:attribute>
      <patch:attribute name="lowercaseUrls">true</patch:attribute>
    </add>
    <add name="multilangProvider" type="Sitecore.XA.Foundation.Multisite.LinkManagers.LocalizableLinkProvider, Sitecore.XA.Foundation.Multisite"
         cacheExpiration="5" addAspxExtension="false" alwaysIncludeServerUrl="false"
         encodeNames="true" languageEmbedding="always" languageLocation="filePath" 
         lowercaseUrls="true" shortenUrls="true" useDisplayName="true"/>
  </providers>
</linkManager>
2

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.