ContentPublishedEventArgs - get which Language Variant is being published
Hi,
I am in the process of setting up Indexing to an external API and I need to find a way to know which Language variant is currently being Published.
I am using the following code and needed a way to pick out the current language - at the moment publishedPageCulture is saying it is the default language and not the correct language.
private void IndexPage(ContentPublishedEventArgs e)
{
// Find the core settings page
int thisPage = e.PublishedEntities.Select(x => x.Id).FirstOrDefault();
var umbracoHelper = Umbraco.Web.Composing.Current.UmbracoHelper;
IPublishedContent currentPage = umbracoHelper.Content(thisPage);
string publishedPageCulture = PublishedContentExtensions.GetCultureFromDomains(currentPage);
any ideas on how I can get the correct language variant?
If you loop over the AvailableCultures iin the IContent that is being sent to you in the ContentPublishedEventArgs you should be able to do as following:
private void IndexPage(ContentPublishedEventArgs e)
{
foreach(var content in e.PublishedEntities)
{
foreach(var culture in content.AvailableCultures)
{
var isPublished = e.IsPublishedCulture(content, culture);
}
}
}
Remember that if you do access the umbracoHelper.Content(id) it wont be the newest version of your content as the cache has not yet been refreshed. So I suggest, depending on your need, to stick with just the IContent from the event args. :-)
ContentPublishedEventArgs - get which Language Variant is being published
Hi,
I am in the process of setting up Indexing to an external API and I need to find a way to know which Language variant is currently being Published. I am using the following code and needed a way to pick out the current language - at the moment publishedPageCulture is saying it is the default language and not the correct language.
any ideas on how I can get the correct language variant?
Thanks
Jon
Hi Jon.
If you loop over the AvailableCultures iin the IContent that is being sent to you in the ContentPublishedEventArgs you should be able to do as following:
Remember that if you do access the umbracoHelper.Content(id) it wont be the newest version of your content as the cache has not yet been refreshed. So I suggest, depending on your need, to stick with just the IContent from the event args. :-)
Hope it helped a little bit.
Regards Malthe
is working on a reply...