More in this section

Forums / Developing with Sitefinity / Filter blog post

Filter blog post

3 posts, 0 answered
  1. kevin croke
    kevin croke avatar
    6 posts
    Registered:
    11 Sep 2009
    31 Mar 2013
    Link to this post
    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


  2. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    31 Mar 2013 in reply to kevin croke
    Link to this post
    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
  3. kevin croke
    kevin croke avatar
    6 posts
    Registered:
    11 Sep 2009
    31 Mar 2013 in reply to Daniel Plomp
    Link to this post
    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.
3 posts, 0 answered