More in this section

Forums / Developing with Sitefinity / Widget Template Filter Expression - Current User

Widget Template Filter Expression - Current User

3 posts, 0 answered
  1. Ian
    Ian avatar
    7 posts
    Registered:
    25 Jun 2012
    08 Aug 2012
    Link to this post
    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


  2. Kristian Smilenov
    Kristian Smilenov avatar
    32 posts
    Registered:
    18 Mar 2015
    13 Aug 2012
    Link to this post
    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
  3. Ian
    Ian avatar
    7 posts
    Registered:
    25 Jun 2012
    30 Aug 2012
    Link to this post
    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
3 posts, 0 answered