Try our conversational search powered by Generative AI!

Get Expiration date from Master language content

Vote:
 

I have multiple languages enabled in our CMS application. We expect users to enter the expiration date on the content when initially published in master language (english). When the pages are translated, I am trying to tap into the Save event to apply the expiration date from the master language content to the new language.

I tried using content loader with new LoaderOptions() { LanguageLoaderOption.Specific(CultureInfo.GetCultureInfo("en")) } and no matter what I use, specific/fallback/fallbackwihtmaster I am always presented the content in the current language branch and not from the master.

Is there something I am doing wrong here ?

#257316
Jun 29, 2021 19:51
Vote:
 

Hi, that is very simple but please post your detail code here so we can figure out what's wrong!

Basically, it should be:

var contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>();
var loaderOptions = new LoaderOptions { LanguageLoaderOption.MasterLanguage() };
contentLoader.TryGet<IContent>(contentLink.ToReferenceWithoutVersion(), loaderOptions, out var masterVersion);

or

var contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>();
var loaderOptions = new LoaderOptions { LanguageLoaderOption.Specific("en") };
contentLoader.TryGet<IContent>(contentLink.ToReferenceWithoutVersion(), loaderOptions, out var masterVersion);
#257370
Jun 30, 2021 7:19
Vote:
 

Thanks for the input. This is Working. 

The difference was that I was not using .ToReferenceWithoutVersion(). 

For reference below was my code

            if (args.Content is CategorizablePageWithImage categorizable)
            {
                if (!categorizable.IsMasterLanguageBranch)
                {                    
                    _contentLoader.TryGet<CategorizablePageWithImage>(categorizable.ContentLink, new LoaderOptions { LanguageLoaderOption.MasterLanguage() }, out var masterLanguageContent);
                    var expiryDate = (masterLanguageContent as IVersionable).StopPublish;

                    categorizable.StopPublish = expiryDate;
                }

            }

#257381
Jun 30, 2021 14:04
Quan Mai - Jul 01, 2021 19:58
good thing that you are using dependency injection :)
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.