Zum Inhalt springen

The new possibilities of DisplayCond

Introduction

For many years, it has been possible to display selected fields only for a specific context.

For example, the extension developer could specify that field X should only be displayed if field Y contains a previously specified value. TYPO3 itself also makes use of this option in the area of content elements. If you select "Text" as the content type, completely different fields are displayed for editing than, for example, for the "Images" or "Form" type.

The extension developer can control this activation/deactivation of fields via the "displayCond" property within the TCA. However, there is one restriction: only ONE condition can be specified per field. Although it is possible to query whether a field has the value x, y or z, there is no way to query whether extension x is installed AND that another field has a certain predefined value.

Here is an excerpt of what is possible so far:

Simple example

'street' => array(
  'displayCond' => 'EXT:test123:LOADED:FALSE',
  'label' => 'street',
  'config' => array(
    'type' => 'input',
    'size' => 30
  ),
),

As of TYPO3 6.1

The core developers have tidied up the displayCond area enormously and added the option of specifying multiple conditions. The source code now queries whether the value for displayCond is a string, in which case only one condition is possible, as in the example above, or an array, in which case the full load of multiple and nested conditions is available. Here are a few examples:

AND condition

'street' => array(
  'displayCond' => array(
    'AND' => array(
      'EXT:test123:LOADED:FALSE',
      'FIELD:title:REQ:TRUE',
    ),
  ),
  'label' => 'Street',
  'config' => array(
    'type' => 'input',
    'size' => 30
  ),
),

The street field is only displayed if the extension test123 is not loaded and the title field has a value.

OR condition

'street' => array(
  'displayCond' => array(
    'OR' => array(
      'EXT:test123:LOADED:TRUE',
      'FIELD:amount:<:10',
    ),
  ),
  'label' => 'street',
  'config' => array(
    'type' => 'input',
    'size' => 30
  ),
),

The street field is only displayed if either the extension test123 is loaded OR the amount field has a value of less than 10.

Nested conditions

'street' => array(
  'displayCond' => array(
    'AND' => array(
      'EXT:test123:LOADED:TRUE',
      'OR' => array(
        'FIELD:amount:<:10',
        'FIELD:excludes:>:5',
      ),
    ),
  ),
  'label' => 'street',
  'config' => array(
    'type' => 'input',
    'size' => 30
  ),
),

displayCond in FlexForms

<field1>
  <TCEforms>
    <label>Field 1</label>
    <config>
      <type>input</type>
      <size>30</size>
    </config>
  </TCEforms>
</field1>

<field2>
  <TCEforms>
    <label>Field 2</label>
    <config>
      <type>input</type>
      <size>30</size>
    </config>
  </TCEforms>
</field2>

<cond>
  <TCEforms>
    <label>Test condition</label>
    <displayCond>
      <AND>
        <numIndex index="0">FIELD:field1:REQ:TRUE</numIndex>
        <numIndex index="1">FIELD:field2:REQ:TRUE</numIndex>
        <OR>
          <numIndex index="0"><![CDATA[FIELD:field1:<:12]]></numIndex>
          <numIndex index="1">FIELD:field2:>:20</numIndex>
        </OR>
      </AND>
    </displayCond>
    <config>
      <type>input</type>
      <size>30</size>
    </config>
  </TCEforms>
</cond>
Updated: 17.07.2024