Using filters to assemble content dynamically

About this task

One way to put filtering to use is through the dynamic assembling of content. By default, you add specific Component Presentations to a Page before publishing occurs. The resulting Web page always shows the same Component Presentations.

In some cases, however, you may want to determine which Component Presentations to pick based on dynamic criteria. For example, you may want to display the five most recently published Component Presentations, or all Component Presentations that have been marked 'sports'. To do this, you use a filter to assemble content dynamically.

In this scenario, you do not specify a fixed set of Component Presentations to add to a Page. Rather, you specify a query consisting of content criteria and then include (some or all) Components that meet those criteria. Using queries to select a number of Dynamic Component Presentations is known as filtering.

Procedure

  1. Decide what type of filter you want to make. Some typical types of filters are:
    Related Items filter
    select Component Presentations based on one or more Keywords.
    Most Visited Components filter
    select Component Presentations based on the number of times they were accessed (this requires implementation of Tracking, see Profiling and personalization).
    Most Recently Published Components filter
    select Component Presentations based on their Initial Publication Date.
  2. If the type of information you are filtering on is not included in the standard metadata of a Component, create custom metadata (for example, Categories and Keywords) for this information.
  3. Publish the Component Presentations you want to filter on as Dynamic Component Presentations.
  4. Create a Page Template that uses the Query class to create and execute a query using the executeQuery or ExecuteQuery method.
    The query returns an array of Component URIs. Combine these Components with a Component Template of your choice to produce the Component Presentations you want to show.
  5. You can configure the results of the query in the following ways:
    • You can restrict the number of Components to a specific number.
    • You can sort the result on a specific metadata field.
    • You can specify a sort direction (ascending/descending).
  6. Create a Page without adding any Component Presentations to it, and associate it with the Page Template you just created.
  7. Publish this Page and examine the result on the Web site.