+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Filtering out a Category in News VIew

Filtering out a Category in News VIew

8 posts, 1 answered
  1. William
    William avatar
    108 posts
    Registered:
    15 Feb 2011
    16 Nov 2011
    Link to this post
    Hey Telerik,

    I'm using 3.7 and running into a situation with News View that I was hoping you could help me with.  Basically, I have a ton of news items that are published and live that have unassigned categories... in other words, a category of "Uncategorized".

    I also have news items recently created, meant for a different area of the site, with a category of "Announcements".

    The question.  Using NewsVIew, how do I display *only* Uncategorized news items and not the news items in my new category?  I see options to display by category on the designer, but no option to select Uncategorized as a choice.  Basically, what I'd love to do is either display only Uncategorized items, or just prevent all items from my new category from being displayed.

    I'm assuming there's some kind of template extension needed here.  If so, could you toss me a sample code-behind that I should use? If not, is there an easier way to accomplish this?

    Thanks much

    - William


  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    17 Nov 2011
    Link to this post
    Hi William,

    There is a FilteExpression property under the advanced tab of the control that you can try to use with parameter Category = "name of your category". When an item is not categorized it shouldn't be added to "Uncategorized" category, so I am not 100 % sure that if you pass an empty string this will work.

    Programmatically you can get all news items and call GetMetaData("Cagegory"). If the value is null then you add the category to a new queriable list and then display the items on a page.

    All the best,
    Ivan Dimitrov
    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
    Answered
  3. William
    William avatar
    108 posts
    Registered:
    15 Feb 2011
    17 Nov 2011
    Link to this post
    Hi Ivan,

    I'll check out the null value into that filter space in the Advanced tab and see if that works in the short term.  I was thinking more of doing this programmatically, but in order to do that, I'd have to extend the template and include a code-behind class, correct?  If that's the case, any way you could toss me an example of what that code-behind might look like for a category filter on NewsView?  I'm not sure exactly what to extend there and what the class file would look like and where to put that filter in the code.

    Worst case, I can just build a custom control, but I'd rather just extend the existing NewsView if that's possible.

    Thanks much.

    William
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    17 Nov 2011
    Link to this post
    Hi William,

    You can take a look at



    Kind regards,
    Ivan Dimitrov
    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
  5. William
    William avatar
    108 posts
    Registered:
    15 Feb 2011
    17 Nov 2011
    Link to this post
    Hey Ivan,

    I think you may have misunderstood my question.  I've read those areas of the developer guide before, but they don't relate to what I'm trying to do here.  What I need to do ideally is extend a template.

    I have the NewsView module on my page, which is using the ListPageMaster template.  I need to modify NewsView via that template to exclude a category of news.  What I'm assuming is that I need to extend ListPageMaster using the usual methods of extending templates.  What I don't know is how to create a code-behind for my extended ListPageMaster, what that class would look like, and where the filtering line would go to filter out the results.

    Is that something you can help me with?

    Thanks

    - William

  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    18 Nov 2011
    Link to this post
    Hi William,

    This is a  standard ascx with an ASP.NET controls in it - repeater, label, hyperlink etc. There is nothing more than using the template as standard user control.

    Best wishes,
    Ivan Dimitrov
    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
  7. William
    William avatar
    108 posts
    Registered:
    15 Feb 2011
    18 Nov 2011
    Link to this post
    Hey Ivan,

    Then I guess I'm a little lost here.  I'm wanting to use NewsView as it is out-of-the-box, with the existing designer continuing to look like it looks and do its functions and affecting data as it always has.  All of the functions of the designer for NewsView are being used by the client, except for the category filter of course.  So, regardless, I'd have to use the same designer for the control.

    So, using the template as a standard User Control or extending the template, I'd still have to grab the News Items exactly as the out-of-the-box NewsView is grabbing them, using the same data pulls, classes, filters, advanced options, etc based on the designer that NewsView is using.  It needs to be a mirror copy of how NewsView works today.

    My challenge is that I have to intercept the data that NewsView is using and filter that programmatically to remove my Announcements category before it hits the repeater.  Or, I have to extend the base class of the existing NewsView and somehow add an additional filter from there.  But in doing that, I have to be using whatever functions you are using to make NewsView pull data back in based on the designer and all the other pieces that NewsView is using.  Since there isn't a code-behind I can see, I of course can't see what that looks like.

    If it were a case of just building a custom user control that pulls in News, that's pretty easily done.  But it's a bit more than that.  If it turns out that this is too complex a task to try to pull-off, that's good to know too.  However, I'd figured it was just another template extension with some code-behind magic.

    Maybe I'm not understanding you here as well. 

    Thanks for your continued help.

    - Williiam

  8. William
    William avatar
    108 posts
    Registered:
    15 Feb 2011
    28 Nov 2011
    Link to this post
    Btw, I went the simpler Category Filter approach, using a null value, which worked like a champ.

    Thanks, Ivan.
Register for webinar
8 posts, 1 answered