We create a TBB to generate web sitemap XML. The problem is if a page is published in child publication, but not published in parent publication. when we generate the sitemap XML in parent publication, it will be in. But we expect it will not in the parent publication sitemap XML because this page is not published.

The code to generate the xml is: enter image description here

2 Answers 2


Try this function for checking the page is published or not:

private bool IsPublished(Page page)
    if (Engine.PublishingContext?.PublicationTarget != null)
        return PublishEngine.IsPublished(page, Engine.PublishingContext.PublicationTarget, true);
    if (Engine.PublishingContext?.TargetType != null)
        return PublishEngine.IsPublished(page, Engine.PublishingContext.TargetType, true);
    //For preview we always return true - to help debugging
    return true;

Also, refer to the DXA GenerateSitemap template code block for your reference.

I hope it helps.


Although Velu provided you with the code sample, you should understand what IsPublished() overload methods do. There are few overload methods and most of them are combinations of the same parameters (if item is published to some publication target or not, or to some target type).

What you need to take a detailed look in Velu's code is the "true" parameter at the end, which shows "isPublishedInContext", so it checks if the item is published in the current publication. That is the main thing which causes your issues. So whenever you do these kinds of checks per publication, you need to check if the item is published in the current publication (and not all publications).


To clarify the difference between Target Type and Publication Target, you need to know with which version you are working with. In 2013 and earlier, Target Type and Publication Target were similar, were Target Type was a higher level of abstraction of Publication Target. In Web 8 and later, Publication Target shouldn't be used. You should use Target Type or Purpose (either one will suffice). Publication Target is still there for legacy publishing model.

  • what's the difference between publication target and target type?
    – Ivy Chen
    Nov 26, 2019 at 8:12
  • I have added my update to the answer Nov 26, 2019 at 8:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.