在 sitecore 中以编程方式在内容编辑器中切换语言
Switch between languages in content editor programmatically in sitecore
我想在 sitecore 中保存项目后以编程方式在内容编辑器中切换语言
实现预期结果的一种方法是向 saveUI
管道添加一个处理器,该处理器将引用 ContentEditorDataContext
并更改其语言。为此,我们需要使用 Process
方法创建一个 class,如下所示:
public class LanguageChangeAfterSave
{
public void Process(Sitecore.Pipelines.Save.SaveArgs args)
{
var contentEditorDataContext = Sitecore.Context.ClientPage.FindControl("ContentEditorDataContext") as Sitecore.Web.UI.HtmlControls.DataContext;
contentEditorDataContext.Language = Language.Parse("en");
contentEditorDataContext.Refresh();
}
}
并且为了将这个流水线处理器添加到 saveUI 流水线中,我们还创建了一个包含以下内容的 .config 文件,并将其放入 webroot\App_Config\Include\ 目录:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<processors>
<saveUI>
<processor type="YourNamespace.LanguageChangeAfterSave,YourAssembly" />
</saveUI>
</processors>
</sitecore>
</configuration>
我想在 sitecore 中保存项目后以编程方式在内容编辑器中切换语言
实现预期结果的一种方法是向 saveUI
管道添加一个处理器,该处理器将引用 ContentEditorDataContext
并更改其语言。为此,我们需要使用 Process
方法创建一个 class,如下所示:
public class LanguageChangeAfterSave
{
public void Process(Sitecore.Pipelines.Save.SaveArgs args)
{
var contentEditorDataContext = Sitecore.Context.ClientPage.FindControl("ContentEditorDataContext") as Sitecore.Web.UI.HtmlControls.DataContext;
contentEditorDataContext.Language = Language.Parse("en");
contentEditorDataContext.Refresh();
}
}
并且为了将这个流水线处理器添加到 saveUI 流水线中,我们还创建了一个包含以下内容的 .config 文件,并将其放入 webroot\App_Config\Include\ 目录:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<processors>
<saveUI>
<processor type="YourNamespace.LanguageChangeAfterSave,YourAssembly" />
</saveUI>
</processors>
</sitecore>
</configuration>