Listing Object

On every page view, the Listing Object gets created automatically and initially contains the full collection of pages. This collection can be maniupulated by filtering and sorting methods. Therefore it is possible to access the same temporary selection from different methods.

A good example to illustrate the purpose of that object is common overview page. Such a page typically has a menu with some filter and sort buttons as well as a page list showing the matching pages. Since there are separate tools to create the filter menu, the sorting buttons and the page list, the tool for the page list has to keep track of the status of the fiters and sort buttons. So all these tools basically access the same listing object for writing to it or reading from it.

<!-- The filters are influencing the listing by cutting down the selection -->
<div class="filters">
    @t(listFilters)
</div>
<!-- The sort buttons are influencing the listing by changing the order -->
<div class="sort">
    @t(listSort{
        "Original Order": { sortOrder: "asc" },
        "Title": { sortItem: "title", sortOrder: "asc" }
    })
</div>
<!-- Now the actual filtered and sorted list of pages gets read from the listing object -->
<div class="pages">
    @t(listPages { variables: "title, subtitle, text" }) 
</div>

Access the listing object using plain PHP

The automatically created instance of the Listing class is actually a property of the $Automad object an can be access like this:

$Listing = $Automad->getListing();

All PHP code gets parsed internally before any Toolbox methods or extensions! Changes made using these tools or extensions are not available when the PHP code gets parsed. But changes made using plain PHP are visible to all tools or extensions.

See also