Join our community!

Get everything you need to start developing EPiServer solutions.

Programming for a Block not published in Content Area

December 7 2012, 13:49

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();


  • December 7 2012, 17:41

    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.

  • December 10 2012, 11:20

    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.

  • December 19 2012, 16:23

    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;