当您在 EXM 中创建新消息时,没有任何“技巧”能够自动添加新的语言版本,因此我添加了一个新OnItemSave
事件,用于检查项目是否源自基本消息模板并创建新的语言版本 -基于自己的业务逻辑。
配置:
<configuration xmlns:x="http://www.sitecore.net/xmlconfig/">
<sitecore>
<events>
<event name="item:added">
<handler type="ABC.SitecoreExtensions.Handlers.EmailExperienceExtensions, ABC" method="OnItemAdded" />
</event>
</events>
</sitecore>
代码
namespace ABC.SitecoreExtensions.Handlers
{
class EmailExperienceExtensions
{
readonly Sitecore.Data.Database masterDb = Sitecore.Configuration.Factory.GetDatabase("master");
private const string EXM_BASE_EMAIL_TEMPLATE_ID = "{A0EA9681-5C86-43AB-80F7-C522DADF6F12}";
public void OnItemAdded(object sender, EventArgs args)
{
Assert.ArgumentNotNull((object)args, "args");
Item obj1 = Event.ExtractParameter(args, 0) as Item;
if (obj1 == null)
return;
if (obj1.IsDerived(new Sitecore.Data.ID(EXM_BASE_EMAIL_TEMPLATE_ID )))
{
//logic to determine the context site and to pickup the language
....
if (rootItem == null)
{
return;
}
var siteContext = SiteContext.GetSite(rootItem.Name);
var lang = LanguageManager.GetLanguage(siteContext.Language);
Item ca = masterDb.GetItem(obj1.Paths.FullPath, lang);
using (new Sitecore.SecurityModel.SecurityDisabler())
{
try
{
if (0 == ca.Versions.Count)
{
ca.Versions.AddVersion();
}
}
catch (Exception ex)
{
// catch exception
}
}
}
}
}
}