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 with one of the predefined languages to display more information to the user. For the most common languages, automatic detection provides more context for the user.
$variable = 'Some general PHP'\TYPO3\TYPO3 class with fully qualified nameCMS\ Core\ Core\ Environment EnvironmentTYPO3 class with short name\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:`\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`
All named inline code roles show an icon right after the code that opens an infobox with details about it — the language, and for a resolvable PHP class from the TYPO3 Core, its doc comment (if any) and a link to https://api.typo3.org. The code text itself stays plain, selectable text, so it can be copied directly instead of accidentally opening the infobox.
:php: and :php-short:
Use
:php:
and
:php- when the text is a real,
resolvable PHP identifier — a class, method, constant, or function — so
the infobox can tell the reader something genuinely useful about it. If
the tooling has nothing to resolve, the "PHP" tag and the infobox button
are just noise, and worse, they promise a lookup that goes nowhere. In
those cases a plain literal reads more honestly:
-
A TCA key,
CType, array key, or YAML config key looks like it lives in PHP because it is often written inside a PHP array, but the key itself is just a string, not an identifier the PHP domain can resolve. Write it as a plain literal instead:The `enablecolumns` key ...Copied! -
When referencing a class, interface, or similar type on its own, pass the fully-qualified name (leading backslash, full namespace) to
:php-rather thanshort: :php:. It still resolves the infobox content from the FQCN, but displays only the short name, which reads much better inline than the full namespace::php-short:`\TYPO3\CMS\Core\Security\ContentSecurityPolicy`Copied!As of this writing,
:php-only resolves a bare type this way, not a type combined with a method, such asshort: Scope::. For those, usebackend () :php:with the full FQCN instead — it reads longer, but it is the one that actually resolves::php:`\TYPO3\CMS\Core\Security\ContentSecurityPolicy\Scope::backend()`Copied! - When you are talking about a concept rather than naming a specific,
resolvable class — for example "a PreviewRenderer" used generically,
not
Vendor— a plain literal fits better, since there is no single class the infobox could point to.Ext Preview Renderer - Headlines are the one place to leave roles out entirely, including
:php:/:php-— use plain backticks there even for something that would get a role in body text. A role's code styling and infobox button do not read well in a heading, and they disappear wherever the heading's text gets reused as plain text elsewhere — for example a bareshort: :ref:to it falls back to unstyled text instead of keeping the code formatting.