Constant ViewHelper <f:constant>
Note
The constant ViewHelper can display PHP constants only. It cannot be used to display TypoScript Constants or Site settings.
Wrapper for PHPs
constant
function.
See https://www.php.net/manual/function.constant.php.
Source code
Go to the source code of this ViewHelper: ConstantViewHelper.php (GitHub).
Table of contents
Displaying global PHP constants in Fluid
You can display global PHP constants using this ViewHelper
Maximal possible number: {f:constant(name: 'PHP_INT_MAX')}
<f:if condition="{f:constant(name: 'PHP_MAJOR_VERSION')} >= 8">
Using PHP 8.0 or greater
</f:if>
Get class constant
You can display any public class constant from a class within TYPO3,
for example constants from
\TYPO3\
:
Join the <f:link.external uri="{f:constant(name: '\TYPO3\CMS\Core\Information\Typo3Information::URL_COMMUNITY')}">
TYPO3 Community
</f:link.external>!
Using enum cases in Fluid
Cases of enums are objects and not strings or integers. They cannot be directly
output in the template. You can however save them into a variable and
then use their value. For example you can use values of the enum cases in
\TYPO3\
to compare them with a value of your
object:
<f:variable name="imageType"><f:constant name="\TYPO3\CMS\Core\Resource\FileType::IMAGE"/></f:variable>
The image case has the value {imageType.value} and name {imageType.name}:
<f:if condition="{myFile.type} === {imageType.value}">
This file is an image!
</f:if>
Arguments
name
-
- Type
- string
String representation of a PHP constant or enum