Copied to clipboard

Flag this post as spam?

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


  • Jamie Hughes 3 posts 73 karma points
    Oct 04, 2019 @ 14:24
    Jamie Hughes
    0

    Umbraco v8 Model.DescendantsOfType() returning Unpublished Content

    Hi,

    I am running into a little issue where calling Model.Content.DescendantsOfType("ContentTypeAlias") is returning all content nodes including unpublished content.

    One thing to note is I am calling this inside a PartialViewMacroPage.

    2 questions I have are:

    1. Is it a bug that this needs Model.Content rather than just Model like UmbracoViewPage?

    and

    1. Is anyone else experiencing this? The only way I can get around it is by filtering where IsPublished() is true.

    Any help would be appreciated!

    Thanks Jamie

  • Steve Megson 151 posts 1022 karma points MVP c-trib
    Oct 04, 2019 @ 16:07
    Steve Megson
    0

    In theory that should only happen in preview mode. Preview assumes that you want to see the latest version of everything, published or not. Do you have a rogue UMB_PREVIEW cookie set?

  • Jamie Hughes 3 posts 73 karma points
    Oct 08, 2019 @ 13:57
    Jamie Hughes
    0

    Hi Steve,

    Thanks for replying! Just checked now and there is no preview cookie set.

    I thought it may have been a caching issue in the macro when we unpublished the node and it still showed in the list, but then I realised publishing should clear macro caches. It was only when I filtered on that IsPubished() method that the unpublished nodes hid.

    Maybe it is a bug in a site that has had a content migration from v7 to v8? As this is a site that has had that.

    How strange!

  • Steve Megson 151 posts 1022 karma points MVP c-trib
    Oct 08, 2019 @ 15:18
    Steve Megson
    0

    Strange indeed. A few questions to see if I can replicate the problem:

    • which version of v8 are you using?
    • are you embedding the macro in a rich text editor or grid, or using it directly in a template?
    • what are the cache settings on the macro?
    • if relevant, is the macro set to render in editors?
  • Jamie Hughes 3 posts 73 karma points
    Oct 08, 2019 @ 15:24
    Jamie Hughes
    0

    Umbraco version: 8.1.2

    The macro is being used directly in a template and also is not set to render in editors.

    Macro cache settings:

    • Cache period: 600
    • Cache by page: true
    • Cache personalised: false

    I'm not entirely sure if its the macro that's the issue or not to be honest. Was just a thought I had!

  • Steve Megson 151 posts 1022 karma points MVP c-trib
    Oct 08, 2019 @ 16:42
    Steve Megson
    1

    My thought was that macros always render in preview mode inside editors, and this preview result could wrongly be cached and then returned when you view the published page. It looks like this is indeed happening, though of course it's not causing your problem.

    However, it seems that @Umbraco.RenderMacro(alias) also always renders the macro in preview mode, which is less than ideal.

    I suspect that will be interesting to fix, but there's a fairly neat workaround you can use in your macros. If you do this:

    var content = Umbraco.Content(Model.Content.Id);
    

    then content will be the proper published or unpublished version for the current context (actually I think it might try to get the published content when rendered in the editor, but that's not a problem for you).

Please Sign in or register to post replies

Write your reply to:

Draft