Programming for a Block not published in Content Area

Vote:
 

Using a Page - Content Area with blocks, if a block is not published but dragged into content area and the page publshed it was still showing all block content in my Repeater control.

 

I have been able to get around this by using the AccessLevel Read to work as its status but is there a better way or is this a bug?

 

Example

 

IEnumerable<MyCustomBlock> myitems = CurrentPage.ContentAreaName.Contents
.Where(a => a.QueryDistinctAccess(AccessLevel.Read))
.Select(b => b as MyCustomBlock)

rptRepeater.DataSource = myitems;
rptRepeater.DataBind();

#64026
Dec 07, 2012 13:49
Vote:
 

Try using FilteredContents instead of Contents to get the blocks that the current user should see when viewing a page. This handles filtering of access rights, deleted items, non published items and in the future even items that have been personalized and doesn't match the current user.

#64031
Dec 07, 2012 17:41
Vote:
 

Thanks I have tried using FilteredContents but it still gives me the same results, I am not logged into to episerver as I am testing via anouther browser and cleared full session and cache, still seems to be a bug unless I need to specifiy more on the filteredcontents.

Will leave with AccessLevel.Read check for now as this gives me the results I need and see if I can find any more on this issue.

#64058
Dec 10, 2012 11:20
Vote:
 

I have reported a bug that the FilteredContents property does not do filtering for access rights etc. Until this has been fixed you can use the FilterContentsForVisitor filter. Something like this:

var content = someContentArea.FilteredContents;
new FilterContentForVisitor().Filter(content);
return content;

#64409
Dec 19, 2012 16:23
Vote:
 

the problem still if the block is Expired the FilteredContents dosn't work. Somebody know how to filtred on the blocks not expired?

#87569
Edited, Jun 17, 2014 12:12
Vote:
 

If you are using EPiSerer 7.5 you should be able to use the FilteredItems property.

#87608
Jun 18, 2014 7:31
Vote:
 

Nope. I can't get FilteredItems to work in EPiServer 7.5 either. Blocks that are scheduled for publish at a later date still shows up in FilteredItems.

#112259
Oct 27, 2014 9:54
Vote:
 

Update to my previous post. It seems that the filtering works fine if the block has never been published (and then using FilteredContents is sufficient. But if the block once has been published and you set a future publish date, the filtering does not work. None of the following filter methods work if the block has once been published:

var items = CurrentBlock.Offers.FilteredItems;

var offers = items.Select(i => contentRepository.Get<BlockData>(i.ContentLink) as IContent).ToList();
new FilterPublished().Filter(offers);

offers = offers.FilterForVisitors().ToList();

OffersListView.DataSource = offers;
OffersListView.DataBind();


Hoping this helps someone
Alex

#112285
Oct 27, 2014 13:31
Vote:
 

Hi!

I cannot reproduce what you are saying with the latest packages. I have four items, one of them is a published block that I have changed the publish date till next year. When I call the FilteredItems method I only get three items but the Items property returns all four.

#112591
Oct 30, 2014 16:08
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.