SaaS CMS has officially launched! Learn more now.

ContentLoader and content.IsPublished() returning true for content that hasn't been published yet.


Im using the content loader to find the Url for content in another language and if it doesn't exist i check if a fallback is available and will still route to that page. The problem is the page.IsPublished() and publishedInLanguages are returning true even though the the StartPublish is 2 days away.

    private string GetLanguagePageUrl(string code, Guid contentGuid)
        var language = new CultureInfo(code);

        if (_contentLoader.TryGet(contentGuid, language, out SitePageData page) && page.IsPublished())
            var isPublished = page.IsPublished(); //This is true
            var publishedInLanguages = page.PublishedInLanguage(); //Returns the page which is currently not published yet
            return UrlResolver.Current.GetUrl(page.ContentLink, code);

        return IsFallbackAvailable(contentGuid, language) ? UrlResolver.Current.GetUrl(page.ContentLink, code) : $"/{code}";

Jan 23, 2024 8:57

Switching to the IPublishedStateAssessor.IsPublished() seems to work however a similiar issue is occuring where i want to check if their is a language fallback available that is published but since the page exists the ContentLoader returns the version that matches the country code but it is unpublished.

    private bool IsFallbackAvailable(Guid contentGuid, CultureInfo language)
        var loaderOptions = new LoaderOptions().Add(LanguageLoaderOption.Fallback(language));
        if (!_contentLoader.TryGet(contentGuid, loaderOptions, out SitePageData page))
            return false;

        return _publishedStateAssessor.IsPublished(page);
Jan 23, 2024 9:15

Where is that IsPublished() defined? I don't recognize it 

Jan 23, 2024 9:54

It is apart of EpiServer.Cms.Shell IContentExtension I'm on CMS v12 but the docs only go up to CMS11.

Jan 23, 2024 10:11

I would say using IPublishedStateAssessor is the right approach as it also checks for IsPendingPublish and optinal conditions. I just looked into IsPublished and it simply checks if the content status is Published. 

Also PublishedInLanguage is an extension in Find, you might want to write something else yourself to have more control over. for example. GetLanguageBranches to get content in all languages then IPublishedStateAssessor to see if each of them is published or not 

Jan 23, 2024 10:59

I ended up going with this approach and using the IContentLanguageSettingsHandler to fetch all of the fallback languages and checking if atleast one is published, thanks for the help.

Jan 23, 2024 11:02
* 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.