Widget Template Filter Expression - Current User
Hi
I have created a custom content type and added a couple of extra single line text fields, now using a widget template on the home page I would like to filter these values by the current logged in user.
I have followed advice found on the forums with the main being:
Edit widget template > Advanced > Control Definition > Views > DynamicContentMasterView
... then edit the FilterExpression property.
I have tried allsorts of combinations but havent got it working even with hardcoding the current user.
By default the content type gives a field called AUTHOR and looking at the code behind these seemingly translates to OWNER. This got me a step further but I have tried things like OWNER.Contains(), OWNER = , OWNER Like and I am recieving errors each time. I believe this maybe because the field is a Guid and I am trying to compare it to a string, so how do I get the GUID of the current logged in user?
Many thanks for your time
Ian
Hello Ian,
You can achieve this kind of filtering by implementing custom DynamicContentView which uses custom DynamicContentViewMaster.
1. Create custom DynamicContentViewMaster and override the InitializeControls method
this
.ConfigurePager(
this
.DataSource.Count());
var dataSource =
this
.GetDataSource();
//apply your filtering here
//var filteredDataSource = ........
this
.DynamicContentListView.DataSource = filteredDataSource.ToList();
this
.DynamicContentListView.ItemDataBound +=
new
EventHandler<RadListViewItemEventArgs>(
this
.DynamicContentListView_ItemDataBound);
if
(
this
.EnableSocialSharing ==
true
)
AddSocialSharing();
Thanks Kristian for the solution.
Apologies for the late correspondance as I have been on vacation.
I have never done this before. How would I go about creating a customer DynamicContentView?
Is it just a class that inherits from the DynamicContentView class, which is then registered in Sitefinity?
Regards
Ian