Retrieve filtered data from the database and pass to the template