Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TASK] Improve constants ViewHelper page #96

Merged
merged 1 commit into from
Mar 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 67 additions & 4 deletions Documentation/Global/Constant.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.. This reStructured text file has been automatically generated, do not change.
.. Source: https://github.com/TYPO3/Fluid/blob/main/src/ViewHelpers/ConstantViewHelper.php

:edit-on-github-link: https://github.com/TYPO3/Fluid/edit/main/src/ViewHelpers/ConstantViewHelper.php
:navigation-title: constant

.. include:: /Includes.rst.txt
Expand All @@ -12,5 +8,72 @@
Constant ViewHelper `<f:constant>`
==================================

.. note::
The constant ViewHelper can display **PHP constants** only. It cannot be
used to display `TypoScript Constants <https://docs.typo3.org/permalink/t3tsref:typoscript-syntax-constants>`_
or `Site settings <https://docs.typo3.org/permalink/t3coreapi:sitehandling-settings>`_.

.. typo3:viewhelper:: constant
:source: ../Global.json
:display: tags, description, gitHubLink
:noindex:

.. contents:: Table of contents

.. _typo3fluid-fluid-constant-global:

Displaying global PHP constants in Fluid
========================================

You can display `global PHP constants <https://www.php.net/manual/en/reserved.constants.php>`_
using this ViewHelper

.. code-block:: html

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>

.. _typo3fluid-fluid-constant-class:

Get class constant
==================

You can display any **public** class constant from a class within TYPO3,
for example constants from :php:`\TYPO3\CMS\Core\Information\Typo3Information`:

.. code-block:: html

Join the <f:link.external uri="{f:constant(name: '\TYPO3\CMS\Core\Information\Typo3Information::URL_COMMUNITY')}">
TYPO3 Community
</f:link.external>!

.. _typo3fluid-fluid-constant-enum:

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
:php:`\TYPO3\CMS\Core\Resource\FileType` to compare them with a value of your
object:

.. code-block:: html

<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>

.. _typo3fluid-fluid-constant-arguments:

Arguments
=========

.. typo3:viewhelper:: constant
:source: ../Global.json
:display: arguments-only