We have a list of links set up in the 2sxc content app. What we experience is when we set the status of an item to 'Hide everything' and save. The 'logged out' user will see a Demo link. Is there some way to prevent this behavior? We would expect the module to simply do as it says, and hide the item.
Another think I see is that there are 3 types of status:
So when I try to set it to Hide, then save and come back, the status is set to Draft.
Specific issue: when you set an item's Status to hide/draft, the editors still see the real item and the Toolbar gets an extra "eye" icon. But the anonymous user now sees the placeholder (demo) item instead. This is usually very undesirable.
Two main solutions:
If you do not need the View to have the placeholder/demo item functionality, unassign it in the view. Fixed, nothing will show.
If the placeholder/demo item is required (editing is more of a builder scenario), then the View code can handle the situation using Request.IsAuthenticated, item.IsPublished, and item.IsDemoItem.
This is an interesting issue where 2sxc is not doing what you expect because the View has a "demo item" assigned. Which is useful in the content app, when the site editors are constantly building pages over time. As a developer or editor, you would want to see the hidden items when logged in (probably marked as hidden, but visible so you can edit and/or change them back to not-hidden). But as a public/anonymous you would not.
For some reason, 2sxc has always defaulted to showing the placeholder (demo) item from the View in this situation.
So its easy enough to handle, it just means that each time you make or modify a view where you want the behavior the way you are suggesting.
You need to know
That last one changes based on the first two. For basic content items that show just one item you can simply detect and exit from the view outputting nothing like this:
// if the current user is anonymous and the item is a demo, exit the View w/o displaying anything.
if(!Request.IsAuthenticated) {
if(Content.IsDemoItem ?? false) {
return;
}
}
If you are dealing with a list of items where 1 or more might be hidden, then it depends on your coding style. Here is an example where I am doing it in LINQ using .Where()...
<p>None of these items are hidden</p>
@foreach (var item in AsList(Data)
.Where(item => !(!Request.IsAuthenticated && !item.IsPublished)
)
{
<div>item.EntityTitle</div>
}
That .Where() in English simply says the current user is not authenticated and the current item is not published; so don't include this item in the list.
But that only fixes it for the public. As I said above, editors and admin/hosts would want to see the items.
So instead of using LINQ, leave the items in place in the list, and inside the foreach, test it. If the current user is not authenticated, skip displaying it. If the current user IS authenticated, display it. Also, check if it is not published and indicate that it is hidden.
@foreach (var linkItem in AsList(Data["Default"]))
{
if((!Request.IsAuthenticated) && linkItem.IsDemoItem)
{
// don't show Demo Items to anonymous users
}
else
{
<div>@linkItem.Title @(linkItem.IsPublished ? "" : "(hidden)")</div>
}
}
I hacked these examples together from old projects and retyped them here to fit the context, they are not tested. If you try this and run in to problems, post your code and it should be easy to get what you need to do working. And I'll update my examples if needed.