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:
Is it a bug that this needs Model.Content rather than just Model like UmbracoViewPage?
and
Is anyone else experiencing this? The only way I can get around it is by filtering where IsPublished() is true.
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?
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.
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).
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:
and
Any help would be appreciated!
Thanks Jamie
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?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!
Strange indeed. A few questions to see if I can replicate the problem:
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:
I'm not entirely sure if its the macro that's the issue or not to be honest. Was just a thought I had!
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:
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).is working on a reply...