简体   繁体   中英

How to configure EXM to create new messages with a custom language version, as default

I am trying to configure the EXM root for an Austrian website to create the new messages with a de-AT language version and to have the de-AT language selected as default.

My question is: How can I configure EXM to automatically create a language version for de-AT when a new message is created?

What I've done so far ..

I managed to achieve having the de-AT selected automatically by playing around with the Language - Select the target language field from the Message Context section of the Standard fields - but the actual message item that is created does not contain the de-AT version - and I am getting an error when trying to save the message.

在此输入图像描述

Error message: Edited language version 'German (Austria)' could not be found. It may have been deleted by another user.

As it can be seen in this screnshot, when I open EXM and I create a new message, the de-AT language version is automatically selected. The problem is that the message has no de-AT language version assigned, so it won't allow to save the item.

在此输入图像描述

在此输入图像描述

I think you missed to add language version to standard values of your message template. 消息版本

Templates in EXM works in a same way as anywhere in Sitecore. You should have language versions for your emails under:

  • /sitecore/templates/Email Campaign/Messages
  • /sitecore/templates/Branches/Email Campaign/Messages

None of the 'tricks' worked to automatically add a new language version when you create a new message inside EXM, therefore I've added a new OnItemSave event which checks if the Item is derived from the base Message template and creates a new language version - based on the own business logic.

Config:

<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>

Code

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

    }

}

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM