diff --git a/Documentation/ApiOverview/SiteHandling/AccessingSiteConfiguration.rst b/Documentation/ApiOverview/SiteHandling/AccessingSiteConfiguration.rst index 4b15304d16..9d5f299355 100644 --- a/Documentation/ApiOverview/SiteHandling/AccessingSiteConfiguration.rst +++ b/Documentation/ApiOverview/SiteHandling/AccessingSiteConfiguration.rst @@ -10,9 +10,6 @@ PHP API: accessing site configuration .. contents:: :local: -Introduction -============ - The PHP API for sites comes in two parts: - Accessing the current, resolved site object @@ -27,6 +24,7 @@ current request but based on a page ID or a site identifier. Let us look at both cases in detail. +.. _sitehandling-php-api-access: Accessing the current site object ================================= @@ -114,6 +112,7 @@ API .. include:: /CodeSnippets/Manual/Entity/SiteLanguage.rst.txt +.. _sitehandling-sitesetting-object: The :php:`SiteSettings` object ============================== diff --git a/Documentation/ApiOverview/SiteHandling/SiteSettings.rst b/Documentation/ApiOverview/SiteHandling/SiteSettings.rst index c4f0d4edfb..b39d65641d 100644 --- a/Documentation/ApiOverview/SiteHandling/SiteSettings.rst +++ b/Documentation/ApiOverview/SiteHandling/SiteSettings.rst @@ -6,6 +6,8 @@ Site settings ============= +.. contents:: Table of contents + .. versionadded:: 13.1 Site settings can receive a type, a default value and some documentation in :ref:`site settings definitions `. It is @@ -78,11 +80,42 @@ Add settings to the :file:`settings.yaml `: :yaml:`categoryPid`. -.. index:: Site handling; TypoScript access to settings .. _sitehandling-settings-access: +Accessing site settings +======================= + +In PHP you can access the :php-short:`\TYPO3\CMS\Core\Site\Entity\SiteSettings` +from the :php-short:`\TYPO3\CMS\Core\Site\Entity\Site` object via +`getSettings()`. (See +`Accessing the current site object `_). + +.. _sitehandling-settings-access-extbase-fluid: + +Site settings in Extbase Fluid plugins +-------------------------------------- + +At the time of writing site settings are not available in Extbase controllers or +plugins unless they have been passed on to the plugin settings via TypoScript +or made available in the controller. + +To make the site settings available to all templates in your controller +you can override method `AbstractController::initializeView()` and assign +the site to the view: + +.. literalinclude:: _Settings/_ExampleController.php + :caption: EXT:myvendor/my-extension/Classes/Controller/ExampleController + +You can then use the variable `{site.settings}` to access the site settings: + +.. literalinclude:: _Settings/_ExampleControllerIndex.html + :caption: EXT:myvendor/my-extension/Resources/Private/Templates/Example/Index.html + +.. index:: Site handling; TypoScript access to settings +.. _sitehandling-settings-access-typoscript: + Accessing site settings in page TSconfig or TypoScript -====================================================== +------------------------------------------------------ .. code-block:: typoscript diff --git a/Documentation/ApiOverview/SiteHandling/_Settings/_ExampleController.php b/Documentation/ApiOverview/SiteHandling/_Settings/_ExampleController.php new file mode 100644 index 0000000000..9aa57b22c3 --- /dev/null +++ b/Documentation/ApiOverview/SiteHandling/_Settings/_ExampleController.php @@ -0,0 +1,21 @@ +view->assignMultiple([ + 'site' => $this->request->getAttribute('site'), + ]); + } + public function indexAction(): ResponseInterface + { + // Variable '{site}' is automatically available + return $this->htmlResponse(); + } +} diff --git a/Documentation/ApiOverview/SiteHandling/_Settings/_ExampleControllerIndex.html b/Documentation/ApiOverview/SiteHandling/_Settings/_ExampleControllerIndex.html new file mode 100644 index 0000000000..aa5be8c5a0 --- /dev/null +++ b/Documentation/ApiOverview/SiteHandling/_Settings/_ExampleControllerIndex.html @@ -0,0 +1 @@ +{site.settings.mywebsite.example}