Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jon 92 posts 166 karma points
    Mar 19, 2021 @ 10:24
    Jon
    0

    Publish one Culture picks up all cultures in ContentService.Published

    Hi, We have a site that uses an external search agent and we need a way to Index a page when a page is Published.

    We have 2 cultures, English and Welsh. We are currently hooking into the ContentService.Published event but I cant see a way how we can only Index the correct Published Culture. For example: English is the Default language BUT when we publish ONLY the Welsh culture BOTH cultures are picked up in the Event.

    Is there a way to only Index the correct culture?

    We are currently using this:

      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);
    
            foreach (string lang in currentPage.Cultures.Keys)
            {
    
               IndexHelper inHelper = new IndexHelper();
    
                    inHelper.AddPageToIndex(currentPage.Url(lang), thisPage, lang);
    
            }
        }
    

    Thanks

  • Malthe Petersen 68 posts 383 karma points c-trib
    Mar 19, 2021 @ 19:48
    Malthe Petersen
    0

    Hi Jon.

    You can check for each culture whether it has been published in the current event, by calling a method on the event args.

    I have answered one of your previous posts with how to check what culture(s) that has been published.

    https://our.umbraco.com/forum/using-umbraco-and-getting-started/104998-contentservicepublished-get-culture-language-of-published-page

    Hope this can get you further.

    Regards

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies