From cdf5ec120877d51d02867ac7d6d8cf48f56b7c67 Mon Sep 17 00:00:00 2001 From: Sybille Peters Date: Tue, 5 Oct 2021 13:29:01 +0200 Subject: [PATCH] Add information about accessing TypoScript The information about accessing TypoScript is missing in extensions. This patch adds the information for Extbase controllers (and refers to existing documentation). Information about how to access TypoScript outside of Extbase controllers can be added in future patches. Related: #463 --- .../AccessTypoScriptWithExtensions.rst | 66 +++++++++++++++++++ Documentation/UsingSetting/Index.rst | 1 + 2 files changed, 67 insertions(+) create mode 100644 Documentation/UsingSetting/AccessTypoScriptWithExtensions.rst diff --git a/Documentation/UsingSetting/AccessTypoScriptWithExtensions.rst b/Documentation/UsingSetting/AccessTypoScriptWithExtensions.rst new file mode 100644 index 00000000..a71e59bb --- /dev/null +++ b/Documentation/UsingSetting/AccessTypoScriptWithExtensions.rst @@ -0,0 +1,66 @@ +.. include:: /Includes.rst.txt +.. index:: TypoScript in extensions +.. _extdev-access-typoscript: + +=================================== +Access TypoScript in your extension +=================================== + +.. note:: + + This part is written for extension developers. + +This page explains how to access TypoScript settings in extensions. + +Extbase controllers +=================== + +In Extbase controllers, :ref:`Flexform settings ` and TypoScript settings will be +merged together. If a settings exists in both, the Flexform takes precedence (and overrides the TypoScript setting). +Keep in mind that both Flexform and TypoScript settings must use the convention of preceding the setting with +`setting.` (e.g. `settings.threshold`). + +Extbase offers some advantages: Some things work automatically out-of-the-box. However, you must stick to the +Extbase conventions ("conventions over configuration"). + +In order to access TypoScript settings from an Extbase Controller. + +.. rst-class:: bignums-xxl + +#. Use the convention of defining your TypoScript settings in :ts:`settings` + + .. code-block:: ts + + plugin.tx_myextension { + view { + # view settings + } + + settings { + key1 = value1 + key2 = value2 + } + } + +#. Access them via :php:`$this->settings` + + For example, in your controller: + + .. code-block:: php + + $myvalue1 = $this->settings['key1'] ?? 'default'; + +.. seealso:: + + * :ref:`settings in Extbase extensions ` + * :ref:`Extbase TypoScript reference ` + +Fluid +===== + +If Extbase controllers are used, :php:`$this->settings` is automatically passed to the Fluid template. Thus, you can +access settings like this: + +.. code-block:: xml + + {settings.key1} diff --git a/Documentation/UsingSetting/Index.rst b/Documentation/UsingSetting/Index.rst index bc7652dd..d5ccabae 100644 --- a/Documentation/UsingSetting/Index.rst +++ b/Documentation/UsingSetting/Index.rst @@ -22,6 +22,7 @@ The TypoScript template configuration can be viewed and edited in the Entering AddTypoScriptWithExtensions + AccessTypoScriptWithExtensions Constants TheConstantEditor Register