Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sitecore Language Embedding multiple sites

I'm looking to run two sites off one Sitecore install.

The first site will only be in UK English therefore I won't include the language in the file path. languageEmbedding=never

The second site will be in multiple languages and I need to include the language in the file path. languageEmbedding=always

Is there a way I can define multiple link managers and configure the sites to use a specific link manager?

like image 386
Tom Dudfield Avatar asked Apr 22 '26 19:04

Tom Dudfield


2 Answers

I've found the best way was to create a custom link manager that supports both scenarios. Then have a supporting config setting which defines whether the language is embedded.

public class LanguageLinkProvider : LinkProvider
{
    public override string GetItemUrl(Item item, UrlOptions urlOptions)
    {
        urlOptions.SiteResolving = Configuration.Settings.Rendering.SiteResolving;
        string sites = ConfigurationManager.AppSettings["EmbedLanguageInUrl"];

        var splitSites = new List<string>();
        if (!string.IsNullOrEmpty(sites))
            splitSites = sites.Split(';').ToList();

        if (splitSites.Contains(urlOptions.Site.Name))
            urlOptions.LanguageEmbedding = LanguageEmbedding.Always;
        else
            urlOptions.LanguageEmbedding = LanguageEmbedding.Never;

        return base.GetItemUrl(item, urlOptions);
    }
}
like image 53
Tom Dudfield Avatar answered Apr 24 '26 08:04

Tom Dudfield


Nope, not by default. But the LinkManager is overrideable. Probably you can change the behavior by selecting a different config per site and coding this into an overriden LinkManager.

like image 40
Alex de Groot Avatar answered Apr 24 '26 09:04

Alex de Groot



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!