Our pages contain a content area that contains a number of blocks, which are then rendered in a list by looping through ContentArea.FilteredItems.
When the blocks are all published, this seems to work fine, but when a block is not published, the contents are not shown when viewing the page, even when in On Page Edit mode.
I thought perhaps this was just some oddity with the way ContentArea.FilteredItems works, so I tried to adjust the template so that it looked at PageEditing.PageIsInEditMode, and if true, instead of looping through ContentArea.FilteredItems, loop over ContentArea.Items instead.
However, when testing this, it appears that even though PageEditing.PageIsInEditMode is correctly identified, both ContentArea.Items and ContentArea.FilteredItems are returning the same result. For example, if I have 2 published blocks and 1 unpublished block in a content area, then both ContentArea.Items and ContentArea.FilteredItems return 2 items, rather than 3. There appears to be no way to retrieve the list of all blocks.
Additionally, if I create a page and add a block to it and publish that block, then go in and edit the block but do not publish, when I preview the page I do not see the unpublished edits, but rather the originally published block, until I republish the block. If I edit a page directly and don't publish the results, I still see the unpublished changes when viewing the page in edit mode, so this doesn't seem to make any sense that blocks work differently.
How can I set this up so that the unpublished blocks can be viewed in Edit Mode, so that authors can validate their work prior to publishing? Is there a bug here somewhere? Do I have something misconfigured?
Have you tried with Projects? What version are you using?
Why not use PropertyFor to render the content area?
Thanks K Khan, I think that is pointing me in the right direction.
This is in version 10.3, and projects is enabled, but the functionality I was seeing (of not previewing unpublished blocks) was occuring when project selection was set to "None (use primary drafts)". If I create a project and then view/edit the blocks on a page, then when I preview the page I see the block changes as they will appear when the project goes live. This is essentially what I want, it just has never been necessary to use projects before to see this behavior.
It seems like the behavior of ContentArea.Items is different now if no project is selected. This doesn't really seem intuitive, since with project set to None, ContentArea.Items and ContentArea.FilteredItems seem to be returning the same data. I wouldn't expect ContentArea.Items to be filtering according to publication status when in Page Edit mode, but it seems like it is unless there is a project active.
This seems weird to me - am I alone?
In the mean time, it seems like using the project functionality would allow us to get the view that we need, perhaps, with just a little set up.
@Per - We have some other logic when looping through the items that determines some wrapping elements that get applied, so PropertyFor doesn't work great for us. Question really boils down to why ContentArea.Items would be filtering based on published status, which doesn't seem intuitive.
@Per - Additionally: went back and adjusted this to use PropertyFor, and behavior is the same. This definitely seems to be driven by the fact that ContentArea.Items filters based on publication status, or some derivative thereof. The previewability of edits mades to blocks is significantly different depending on whether a project is selected or not.
The content areas show the latest published version of the blocks.
There is one exception: When you have a project selected, and work with pages and blocks that belong to that project, then you can see the draft version of the block on the page.
@Per- I am facing the same issue with version=18.104.22.168 any idea how to preview unpublished block in edit view on the local environment? However, I have used PropertyFor for rendering content.
Maybe the BlockEnhancements addon can help? You will get a Content Draft View amongst other things: "The editor can use the new "Content Draft View" button to get an overview of how the page will look after all blocks have been published."
We had a similar issue, which still persisted after installing BlockEnhancements (which is awesome by the way). It turned out to be with how we were handling ContentArea. We needed to manipulate the model prior to calling PropertyFor. I looked at the code in the BlockEnhancements project and found that they had a special content loader CustomContentAreaLoader, which we were bypassing.
Below is a simple partial for ContentArea, which uses the CustomContentAreaLoader to get saved unpublished version of the block, when using the BlockEnhancements preview mode.
IContentAreaLoader contentAreaLoader = ServiceLocator.Current.GetInstance<IContentAreaLoader>();
if (Model.Items != null)
foreach (ContentAreaItem contentAreaItem in Model.FilteredItems)
IContent content = contentAreaLoader.Get(contentAreaItem);
@Html.PropertyFor(m => content)