Filter blog post

Posted by Community Admin on 04-Aug-2018 03:38

Filter blog post

All Replies

Posted by Community Admin on 31-Mar-2013 00:00

I have the following code to grab the blog posts I want:

links.DataSource = App.WorkWith().BlogPosts().Where(bp => bp.Status == ContentLifecycleStatus.Live
                        &&
                        bp.GetValue<string>("SelectedAuthor")
                        .ToLower()
                        .Contains(Name.ToLower()))
                .Get()
                .ToList();
            links.DataBind();

This is the code behind in a module. How do I use this in conjunction with a Sitefinity Control Template?  I click on Design > Widget Templates and there are blog templates. I want the blog template to only show the posts grabbed from the above code.

Thanks,
kevin


Posted by Community Admin on 31-Mar-2013 00:00

Hey Kevin,

I think you should do this with a custom UserControl, as you probably have right now. That would be the easiest way. There is a blog post somewhere on how to change your UserControl so that you can make it editable through the Design -> Widget Templates section. Can't remember it exactly.

One other thing: I don't think it is necessary to call the .ToList() method. The result of this Fluent API call returns an IQueryable which can be bound to the Datasource. A .ToList() will cause an extra call to the database.

Kind regards,
Daniel

Posted by Community Admin on 31-Mar-2013 00:00

Thanks Daniel. I'll try it without the ToList. Now, if I could only find the way to make it editable through the design -> Widget Template section.

This thread is closed