Inline code with or without infoboxes
Hint
Too much inline code can make the information on a page unreadable. If this is the case, consider using Code blocks with syntax highlighting.
Any text inside single or double backticks is printed as inline code. Use single backticks by default; double backticks are only needed when the code itself contains an unescaped backtick:
Code roles with language information and an infobox
You can also use text roles that name the language of the code:
$variable = 'Some general PHP'\TYPO3\TYPO3 class with fully qualified nameCMS\ Core\ Core\ Environment EnvironmentTYPO3 class with short nameGeneralclass memberUtility:: make Instance () \TYPO3\TYPO3 namespaceCMS\ Core\ Http \Symfony\External classComponent\ Dotenv\ Dotenv $GLOBALSconfiguration values['TYPO3_ CONF_ VARS'] ['MAIL'] ['transport'] page = PAGETCAdefaults.pages. hidden <f:debug> {my Variable}</ f: debug> <code>code#mycode{font- family: courier} alert('test') ./vendor/ bin/ typo3 help
* :php:`$variable = 'Some general PHP'`
* :php:`\TYPO3\CMS\Core\Core\Environment` TYPO3 class with fully qualified name
* :php-short:`\TYPO3\CMS\Core\Core\Environment` TYPO3 class with short name
* :php-short:`\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance()` class member
* :php-namespace:`\TYPO3\CMS\Core\Http` TYPO3 namespace
* :php:`\Symfony\Component\Dotenv\Dotenv` External class
* :php:`$GLOBALS['TYPO3_CONF_VARS']['MAIL']['transport']` configuration values
* :typoscript:`page = PAGE`
* :tsconfig:`TCAdefaults.pages.hidden`
* :fluid:`<f:debug>{myVariable}</f:debug>`
* :html:`<code>`
* :css:`code#mycode {font-family: courier}`
* :js:`alert('test')`
* :bash:`./vendor/bin/typo3 help`
Every code role shows an icon right after the code that opens an infobox. For most roles, the infobox only names the language, for example "Code written in SQL". Some roles can tell the reader more:
:php:and:php-, see PHP classes and interfaces.short: :typoscript:and:tsconfig:, see TypoScript and TSconfig.
The code text itself stays plain, selectable text, so it can be copied directly instead of accidentally opening the infobox.
Two text roles that are not code roles open an infobox as well:
:composer:
always does, with information from Packagist, and
:file:
only does for a file that the same manual documents with the
.. typo3: directive.
When to use a code role for inline code
A code role labels its text as code in a language. Use one when the text is code in that language: a statement, an expression, a keyword, a type, or an identifier that the rendering can look up.
Everything else is a plain literal in single backticks. On text that is not code, the language label and the infobox add nothing, and they promise information that is not there.
Plain literals for array keys, configuration keys and column names
A TCA key, CType, array key, or YAML configuration key looks like PHP
because it is often written inside a PHP array, but the key itself is a
string. Database table and column names such as tt_ or pid are
often written next to SQL, but they are names, not SQL. Write all of them
as plain literals:
The `enablecolumns` key ...
The `pid` column of the `pages` table ...
Keep
:sql:
for actual SQL, such as a statement, a keyword like
WHERE
, or a column type like
varchar.
Plain literals for class names used generically
When you talk about a kind of thing rather than one specific class, for example "a PreviewRenderer" used generically, there is nothing a role could resolve. Use a plain literal.
A namespace in a plain literal needs doubled backslashes, for example
\Vendor\: unlike
:php:
, a plain literal
drops a single backslash instead of printing it. See
Backslashes in text roles.
PHP classes and interfaces with :php: and :php-short:
These two roles resolve a PHP type, such as a class or an interface, and a member of one. Always pass the fully qualified name, including the leading backslash: the namespace is what the roles need to find the class. For a type of the TYPO3 Core, the infobox then shows its signature, the summary of its doc comment and a link to https://api.typo3.org. For any other type, for example one from Symfony, it can only say that the text is a class or interface name.
:php:
also recognizes a path in the global configuration, such as
$GLOBALS, and explains
$GLOBALS in its infobox.
Referencing a PHP class or interface with :php-short:
Use
:php-. It resolves the type from the fully qualified name
but shows only the short name, which reads much better inline:
:php-short:`\TYPO3\CMS\Core\Security\ContentSecurityPolicy\Scope`
:php:
resolves the type the same way but prints the full namespace.
Referencing a class member with :php-short:
A method, property, constant or enum case resolves as well, as long as you
write it after the fully qualified class, with :: or ->:
Create a scope with
:php-short:`\TYPO3\CMS\Core\Security\ContentSecurityPolicy\Scope::backend()`.
The text prints as
Scope::.
The infobox names what the member is, for example "PHP function" for a
method, "PHP property", "PHP constant" or "PHP enum case", and describes the
class it belongs to; the link to https://api.typo3.org leads to the member on
the page of its class.
A member written on its own, such as Scope::, has nothing to
resolve without its namespace. Introduce the class once with
:php-, then write the bare member as a plain literal.
Referencing a PHP namespace with :php-namespace:
Use
:php- for a namespace. Pass the fully qualified
namespace, including the leading backslash:
The classes of :php-namespace:`\TYPO3\CMS\Core\Http` handle requests
and responses.
The text prints as
\TYPO3\. The role always
prints the full namespace, because the last segment alone says too little.
The infobox calls it a PHP namespace. For a namespace of the TYPO3 Core, the
infobox also links to the page of the namespace on https://api.typo3.org.
The class index
does not list a namespace.
:php:
and
:php- also recognize a namespace that the TYPO3
API knows, and print it in full. A
use
statement in a code example
that imports such a namespace is recognized too.
Some names are a class and a namespace at the same time, for example
\TYPO3\.
:php:
and
:php- treat
such a name as the class. If you mean the namespace, use
:php-.
TypoScript and TSconfig with :typoscript: and :tsconfig:
The infobox of
:typoscript:
and
:tsconfig:
says what the code
is and links to its description. The rendering reads this from the
configuration values of the
TypoScript reference.
This works in every manual, in the version of the TypoScript reference
that its interlinks use.
The roles find the following:
- A full path to an option, for example
std,Wrap. parse Func page., orinclude JS options..page Tree. doktypes To Show In New Page Drag Area - An object type, a function, or a top-level object on its own, for
example
USER,COA_,INT PAGE,std,Wrap typolink,config, ormodule.
A name that several options share, such as wrap or current, gets no
description. A wrong description is worse than none. Write the full path
instead, for example
std rather than current.
Naming the configuration value in angle brackets
If the code alone does not tell which option it is, name the configuration
value in angle brackets, as in
:confval:
:
Use :typoscript:`current <t3tsref:stdwrap-current>` to ...
The text prints as
current
. The
page shows only the code before the angle brackets.
- The key is the
:name:of the confval. Put an interlink key in front of it, such ast3tsref:ort3coreapi:, for a configuration value of another manual. Without an interlink key, the key names a configuration value of the same manual. - Any configuration value works, not only a TypoScript one. For example, you can name a TCA option.
- The text before the angle brackets must be a path or a name. The
rendering never reads code such as an HTML wrap,
<div>, or| </ div> <INCLUDE_as a key.TYPOSCRIPT: ...>
If the named manual does not document the key, the rendering shows a
warning, and
make test- fails. If the rendering cannot reach
the manual, it shows no warning.