Sitecore Language Embedding multiple sites

拥有回忆 提交于 2019-12-01 06:47:25

问题


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?


回答1:


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);
    }
}



回答2:


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.



来源:https://stackoverflow.com/questions/9570360/sitecore-language-embedding-multiple-sites

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!