Creative Commons License
Tesseract Tutorial: Introducing Filters by François Suter is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
Based on a work at www.typo3-tesseract.com.

Support the project

If you appreciate what the Tesseract project does for you, consider donating to it.

Scenario

In the Getting Started tutorial we drew up a list of web site administrators by displaying be_users records in the TYPO3 frontend. There are several improvements that can be made to this. Let's say that we want to differentiate between BE users with admin rights (true "administrators") and those without ("editors").

This is really the same thing that we did in the first tutorial. We just want to have two views with each a little tweak: one displays only admins, the other only non-admins. Thanks to Data Filters we can achieve this with no duplication of logic nor templating.

Preparing for work

Before starting the actual work, create a new page called "Web site editors" just after the "Web site administrators" we created in the Getting Started tutorial.

Avoiding duplication

As mentioned in the introduction to this tutorial, the main point is to rely on existing Tesseract components as much as possible, to avoid duplication. As a first step copy the "Your administrators" Display Controller content element from the "Web site administrators" page to the newly created "Web site editors" page. Rename it to "Your editors".

Preview in the frontend to make sure that everything went right. You should see the same content, but the page's and the content element's name have changed.

Copy of the existing list

What duplication did we avoid? If you edit the Display Controller element, you will notice that the Data Consumer and the Primary Data Provider are the same as those used on the first page. We didn't have to rewrite our SQL query, nor define the template anew.

Filtering

Let's now filter out the admin use

  1. switch to Web > List mode
  2. create a new Data Filter record

 Creating a new Data Filter record

  1. call it "Editors"
  2. enter "admin = 0" in the "Filter Configuration" field
  3. save

Your data filter should look like this:

The Data Filter setup

The last step is to connect this Data Filter to the other components:

  1. edit the "Your editors" Display Controller
  2. in the "Data Objects" type, choose "Advanced filter" for the field "Type of filter"
  3. in the "Advanced Data Filter (primary) field choose the Data Filter that we just created.

Your setup should look like this:

Binding the Data Filter within the Display Controller

And the output in the frontend should be:

The list of users with only editors (non-admins)

Note how the "admin" user has disappeared.

Exercise

As an exercise repeat the steps from the previous section and add a Data Filter on the "Web site administrators" page, so that only admin users get displayed.

This is what you should get:

The list of users with only administrators