Core documentation code examples

Language

en

Version

13.1

Description

General TYPO3 CMS code examples. Used in particular for maintaining the official documentation.

Keywords

examples, tutorial, documentation

Copyright

2013-2021

Author

TYPO3 Documentation Team

Email

documentation@typo3.org

License

This document is published under the Open Content License available from http://www.opencontent.org/opl.shtml

Rendered

Wed, 21 May 2025 08:44:58 +0000

Introduction

What does it do?

This extension contains a lot of code samples that are used throughout the TYPO3 Core Documentation. The goals are two-fold:

  1. Provide an easy way for users to gain access to these examples for their own use.
  2. Store all code examples and content elements in a central place, so that it is easier for documentation maintainers to reproduce the examples from the documentation, in particular when refreshing the screenshots.

The usage of these examples is not explained in this manual. It is explained in the relevant documentation.

Not all code examples from the Core Documentation will be moved here as it is a rather huge task. Whenever possible code samples are taken from the TYPO3 Core itself. Furthermore priority is given to those code samples that are related to screenshots.

Backend Module

The extension introduces a backend module with different pages that introduce one concept each:

Page Tree

The extension initializes a page tree with custom content elements that introduce further concepts. Currently it contains only one dummy page, but should in perspective contain all custom pages and content needed for the documentation and not provided by other official TYPO3 distributions like EXT:introduction or EXT:styleguide. The latter are not primarily used for documentation.

An export preset "Examples Export Preset" is included in the dataset to export the page tree repeatedly during the development of the distribution, i.e. when having added a new page or content element. Read the manual "Creating a new distribution" for more information on how to reliably export page trees.

Page Tree Examples

Content element example

Data processor examples

RTE Configuration

Extending TCA

Site set settings

Site set settings can be defined through a file like EXT:example/Configuration/Sets/Examples/settings.definitions.yaml.

Here is the auto-generated listing of all definitions. This is for example purposes only, and not yet implemented:

Name Type Label
Site settings examples
Examples
string Path to template root (FE)
string Path to template partials (FE)
string Path to template layouts (FE)
string Doktypes to exclude
string List of page uids which should be excluded recursive
string Additional where clause
Available types
int Type int
number Type number
bool Type bool
bool Type bool
string Type string
text Type text
string Type string with enum
stringlist Type stringlist
color Type text

Example

Example
Label
Site settings examples

Example.examples

Example.examples
Label
Examples

example.output.view.templateRootPath

example.output.view.templateRootPath
Type
string
Default
"EXT:example/Resources/Private/Templates/"
Label
Path to template root (FE)
Category
Site settings examples > Examples

example.output.view.partialRootPath

example.output.view.partialRootPath
Type
string
Default
"EXT:example/Resources/Private/Partials/"
Label
Path to template partials (FE)
Category
Site settings examples > Examples

example.output.view.layoutRootPath

example.output.view.layoutRootPath
Type
string
Default
"EXT:example/Resources/Private/Layouts/"
Label
Path to template layouts (FE)
Category
Site settings examples > Examples

example.output.pages.excludedDoktypes

example.output.pages.excludedDoktypes
Type
string
Default
"3, 4, 6, 7, 199, 254"
Label
Doktypes to exclude
Category
Site settings examples > Examples

example.output.pages.excludePagesRecursive

example.output.pages.excludePagesRecursive
Type
string
Label
List of page uids which should be excluded recursive
Category
Site settings examples > Examples

example.output.pages.additionalWhere

example.output.pages.additionalWhere
Type
string
Default
"{#no_index} = 0 AND {#canonical_link} = ''"
Label
Additional where clause
Category
Site settings examples > Examples

Example.types

Example.types
Label
Available types

example.types.int

example.types.int
Type
int
Default
42
Label
Type int
Category
Site settings examples > Available types

Checks whether the value is already an integer or can be interpreted as an integer. If yes, the string is converted into an integer.

example.types.number

example.types.number
Type
number
Default
3.16
Label
Type number
Category
Site settings examples > Available types

Checks whether the value is already an integer or float or whether the string can be interpreted as an integer or float. If yes, the string is converted to an integer or float.

example.types.bool

example.types.bool
Type
bool
Default
true
Label
Type bool
Category
Site settings examples > Available types

Casts the value to a boolean.

example.types.bool-false

example.types.bool-false
Type
bool
Default
false
Label
Type bool
Category
Site settings examples > Available types

Casts the value to a boolean.

example.types.string

example.types.string
Type
string
Default
"EXT:example/Resources/Private/Templates/"
Label
Type string
Category
Site settings examples > Available types

Converts almost all data types into a string. If an object has been specified, it must be stringable, otherwise no conversion takes place. Boolean values are converted to "true" and "false".

example.types.text

example.types.text
Type
text
Default
"EXT:example/Resources/Private/Templates/"
Label
Type text
Category
Site settings examples > Available types

Exactly the same as the `string` type. Use it as an alias if someone doesn't know what to do with `string`.

example.types.string-enum

example.types.string-enum
Type
string
Default
"summer"
Label
Type string with enum
Enum
{ "spring": "Spring time", "summer": "Seasons in the sun", "fall": "Wine harvest", "winter": "Cold" }
Category
Site settings examples > Available types

Site settings can provide possible options via the `enum` specifier, that will be selectable in the editor GUI.

example.types.stringlist

example.types.stringlist
Type
stringlist
Default
[ "Dog", "Cat", "Bird", "Spider" ]
Label
Type stringlist
Category
Site settings examples > Available types

The value must be an array whose array keys start at 0 and increase by 1 per element. The list in this type is derived from the internal PHP method array_is_list() and has nothing to do with the fact that comma-separated lists can also be converted here. The `string` type is executed for each array entry.

example.types.color

example.types.color
Type
color
Default
"#FF8700"
Label
Type text
Category
Site settings examples > Available types

Checks whether the specified string can be interpreted as a color code. Entries starting with `rgb`, `rgba` and `#` are permitted here. For `#` color codes, for example, the system checks whether they have 3, 6 or 8 digits.

Credits

Some of the examples were originally created by Kasper Skårhøj.

Users manual

If you install this extension, a lot of changes will happen to your TYPO3 backend. Thus you should take care to install it only in a development environment, as you may otherwise run into some surprises.

In various parts of the code contained in this extension, you will find PHP comments that look like this:

// USAGE: TCA Reference > Additional $TCA features
Copied!

This points to which manual (and which part of the manual) refers to the given code sample. This will help you find where to find the related explanations.

For maintainers

Most of the customizations provided by the code samples contained in this example are activated by default. So don't be surprised if you find strange things here and there in your TYPO3 backend.

Whenever possible, the usage of a given piece of code is described in the source code with the following type of PHP comments

// USAGE: Core APIs > TYPO3 API overview > Various examples > Support for custom tables in the Page module
Copied!

This makes it easier to relate a given code sample to a precise place in a manual. The other way round, it should possible to search for a chapter title in the source code and find the relevant code sample.

Code quality

To ensure code quality, some Composer scripts are available. These are run in a Docker container to ensure the same checks as the GitHub action.

composer check
Run all checks
composer check:composer
Run all checks regarding composer.json
composer check:composer:config
Check if composer.json is normalized
composer check:php
Run all checks regarding PHP
composer check:php:cs
Check coding standards
composer check:php:lint
Lint all PHP files
composer fix
Run all fixes
composer fix:composer
Normalize composer.json
composer fix:php
Run all PHP fixes
composer fix:php:cs
Fix coding standard violations

Error handling demonstration

The extension provides a simple FE plugin for demonstrating error handling output in the FE. The settings related to the error handler should be changed to provide different output. It seems hard to get all the possible output, support for all possible settings may be buggy in the Core or has changed over the past and documentation should be adapted accordingly.

Flash messages demonstration

The extension's BE module provide a screen for outputting Flash messages. Code extracts are used in Core APIs.

Flash messages produced by the "Examples" BE module