Widget Template Filter Expression - Current User

Posted by Community Admin on 04-Aug-2018 14:36

Widget Template Filter Expression - Current User

All Replies

Posted by Community Admin on 08-Aug-2012 00:00

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


Posted by Community Admin on 13-Aug-2012 00:00

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();
2. Override the InitializeMasterView Method of the custom DynamicContentView 
this.Controls.Add(this.MasterViewControl);

This should do the trick. 

You can take the id of the currently logged in user this way Telerik.Sitefinity.Security.SecurityManager.GetCurrentUserId();

If you have any other questions, don't hesitate to contact us. Regards,
Kristian Smilenov
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 30-Aug-2012 00:00

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

This thread is closed