|Number of votes:||1|
This technical article describes filters and how to implement them in EPiServer.
A filter is a general mechanism in EPiServer that is used to manage information in listings. As a developer, you can construct your own filters, which can then be used in conjunction with listings to display content in accordance with the specified requirements.
A filter has three primary functions and is used for adding, removing and sorting.
We want to create a property for a page type that determines whether the page is to be displayed on the first page of the Web site. To do this, we link a filter that we have developed to the PageList object, which will only display pages where the property is activated.
The example below describes how to create the FirstPageNews property on the "Ordinary web page" page type.
|Edit heading:||Show on start page|
|Place under heading:||Information|
|Default value:||No default value|
|Value must be entered:||<not selected>|
|Unique value per language:||<not selected>|
Check this property on a few Web pages in the ordinary Web page news folder, so that we have a basis on which to build when we create the listing on the home page.
public class FilterBooleanProperty
public void Filter(object sender, FilterEventArgs e)
PageDataCollection pages = e.Pages;
for (int i = 0; i < pages.Count; i++)
pageData = pages[i];
if (pageData["FirstPageNews"] != null &&
The code above implements the filter method that receives the sender and e arguments, which are object and FilterEventArgs types. The filter method is required to ensure that filtering can be done on a listing. This signature is required in order for it to be called from the event Filter.
The first thing that happens is that you create the pages variable, then turn it into a PageDataCollection and assign it to the content of e.Pages, which contains the pages the filter is to process.
You then loop through pages, checking in each sequence that FirstPageNews property is set to true. If the condition is true, you continue in the loop. Otherwise remove the relevant page from the listing.
In order to activate the filter, you must add the Filter event, which you do in the OnInit event.
override protected void OnInit(EventArgs e)
development.FilterBooleanProperty booleanFilter =
NewsList.Filter += new FilterEventHandler(booleanFilter.Filter);
Add the code marked in bold in the above listing. The first thing that happens is that you create an instance of the new object, FilterBooleanProperty. The Filter method in the object is then linked to the Filter event on the DataList Web check on the home page.