How do I prevent Sitecore from auto-publishing child pages that don't exist?

Hello,

I'm wondering if there's a way to prevent a child page from being created if that content doesn't exist? On our site the default language is English. We have three other languages Japanese, Chinese and Russian. Sitecore will automatically create child pages on the three non English languages regardless if the content exists or not. This has resulted in thousands of 404's on our site. Is it possible to create a rule or something where if the child page content doesn't exist in the non- English languages, to not create that page?  

Regards,

Peter

  • Hi Peter,

    Can you be more specific regarding the issue? Ill try to summarize it below:

    Your site has 4 different languages and English is the default language for it. Whenever a page item is created, it gets created in English version. Since this item does not any version for 3 remaining languages, users are redirected to 404 page.

    If the above scenario is correctly understood by me then you can use a code to redirect the user in English language in Main layout or Master page.

    When the main layout is called. Check if the version exists in the Context language, if not then change the context language to English. Hence all the 404 errors will be resolved.

    Also not to confuse the end user, you can check if the context item has versions in 2 different languages then only enable the language selector else you can disable it.

    Hope this helps.
  • In reply to Rohan Kenkre:

    Hi Rohan,

    Thanks for your comment sorry for the ambiguity. So yes, whenever a page is created the default version is English. Sometimes we don't have a version for say the Chinese, or Japanese pages for example. But, it's still creating the child page because of the parent child relationship. We're wondering if there's a way for sitecore to not create the child pages in other languages if that content does not exist?

    Regards,

    Peter
  • In reply to Rohan Kenkre:

    Hi Rohan,

    Thanks for your comment sorry for the ambiguity. So yes, whenever a page is created the default version is English. Sometimes we don't have a version for say the Chinese, or Japanese pages for example. But, it's still creating the child page because of the parent child relationship. We're wondering if there's a way for sitecore to not create the child pages in other languages if that content does not exist?

    Regards,

    Peter
  • In reply to Peter Rota:

    Peter - Do you mean it's creating the page in menu? Or where exactly are you seeing this page being created. If it's throwing a 404 error, I would assume it's not being created in Sitecore's content tree.
  • In reply to Peter Rota:

     - I just tried with Sitecore 9.2 the same I added English (Default), Chinese and Japanese version to parent items and if I a have selected English back to parent item then creating child item it is not adding versions for child pages automatically.


    Is it your case?

    Item A (Has version in English, Chinese and Japanese)
    child item 1 (While you creating this item it created with all 3 language versions?)


    If this is the case can you please check is there any customization done on your sitecore for same you can find item:create event in your config and see if there is any?

  • In reply to Jaina Baumgartner:

    Hi Jaina,

    So on each page on our site in the menu, we have an option to pick the language. By default, it will create the page in all langues on every page, regardless if content actually exists for that page. We're also able to see the pages when we crawl the pages with a website crawler.
  • In reply to Yogesh Sharma:

    Hi , So in our top nav menu we have an option to pick which language you want the page in. So you can pick English, Chinese, Japanese or Russian. It looks like whenever a English page is pushed live or created, it automatically will create the pages in the other 3 languages regardless if those pages have content on them or not. I will look to see if I can find item:create event in our config.
  • In reply to Peter Rota:

    Hi Peter,

    I got the point, if the page is in English and if user is trying to browse Chinese then since the data is not present either a blank or 404 page appears.

    My suggestion will be check if that particular item has only English version and rest versions should not be present. And while loading that particular page, disable the language selector since you have only one version of that page.

    You can check the versions present for the context item in the language selector view.
  • In reply to Rohan Kenkre:

    Hi Rohan,

    Those are some great ideas. I will look into them and see if we can do it, thanks again for your help!
  • In reply to Peter Rota:

    Why don't you use Language fallback in that case there is no version for item fall back them into English again it's OOTB functionality of Sitecore.
  • In reply to Yogesh Sharma:

    That could work possibly, I will see if that works for our situation.
  • In reply to Rohan Kenkre:

    Hi Rohan, do you know if it's possible say if a page doesn't exist in the other languages to not load the menu selector dynamically? Or, would we need to go to each individual page and check if the content is there for the other pages and then enable the language selector to not show if that's the case?
  • In reply to Peter Rota:

    Hi ,

    You can write an extension method like the following and call it from your code rendering the menu such that you can decide whether you show or hide a menu option for that target language item.

    public static bool HasVersionInLanguage(this Item item, string lang)
    {
    var languageSpecificItem = Sitecore.Context.Database.GetItem(item.ID, lang);
    if (languageSpecificItem != null && languageSpecificItem.Versions.Count > 0)
    {
    return true;
    }

    return false;
    }
  • In reply to Debabrata Biswas:

    Hi , that's another great idea, thank you for sharing!
  • In reply to Peter Rota:

    Thanks. If you feel ok once you try it, you can suggest this as an answer.