|
| 1 | +:navigation-title: Usage in Fluid |
| 2 | + |
| 3 | +.. include:: /Includes.rst.txt |
| 4 | +.. _settings-fluid: |
| 5 | + |
| 6 | +============================================= |
| 7 | +How to use settings as variables in templates |
| 8 | +============================================= |
| 9 | + |
| 10 | +Certain information is used in different parts of the templates over and over |
| 11 | +again like the uid of the data privacy page or the contact e-mail address. |
| 12 | + |
| 13 | +You can keep central information in settings. They can then be adjusted as |
| 14 | +needed in the :guilabel:`Site Management > Settings` module in the backend |
| 15 | +by administrators. |
| 16 | + |
| 17 | +.. _settings-definitions-yaml-constants: |
| 18 | + |
| 19 | +Setting definition |
| 20 | +================== |
| 21 | + |
| 22 | +Settings definitions are used to set values that can be used in the TypoScript |
| 23 | +setup through out the project. |
| 24 | + |
| 25 | +They are stored in the file :file:`settings.definitions.yaml` in your site set. |
| 26 | + |
| 27 | +The settings can be displayed and adjusted in module |
| 28 | +:guilabel:`Site Management > Settings`: |
| 29 | + |
| 30 | +.. figure:: /Images/Settings/SitePackageSettings.png |
| 31 | + :alt: Screenshot of module "Site Management > Settings" with the settings of the example site package open |
| 32 | + |
| 33 | + Administrators can view and adjust settings and save them here. |
| 34 | + |
| 35 | +If administrators change settings here, they get saved to |
| 36 | +:file:`config/sites/my-site/settings.yaml` so this path and file have to be |
| 37 | +writable for TYPO3. If the file is not writable for example when you have it |
| 38 | +under version control, administrators can als export the settings and download |
| 39 | +them. |
| 40 | + |
| 41 | +Let us have a look at the example generated by the |
| 42 | +`Site Package Builder <https://get.typo3.org/sitepackage>`_: |
| 43 | + |
| 44 | +.. literalinclude:: /CodeSnippets/my_site_package/Configuration/Sets/SitePackage/settings.definitions.yaml |
| 45 | + :caption: packages/my_site_package/Configuration/Sets/SitePackage/settings.definitions.yaml |
| 46 | + |
| 47 | +Settings can be assigned to categories so that they are easier to find for |
| 48 | +administrators. These categories are defined in lines 1-12. |
| 49 | + |
| 50 | +Let us now have a look at the definition of a setting entry in detail: |
| 51 | + |
| 52 | +.. literalinclude:: _setting_entry.yaml |
| 53 | + :caption: packages/my_site_package/Configuration/Sets/SitePackage/settings.definitions.yaml (excerpt) |
| 54 | + |
| 55 | +Line 1 defines the identifier of the settings. Identifiers are available |
| 56 | +globally within the complete project and installed extensions might define some. |
| 57 | +Use a unique prefix therefore. Here we use `MySitePackage.`. We used the same |
| 58 | +prefix for the categories. This is suggested but not mandatory in a site package. |
| 59 | + |
| 60 | +Line 2-3 define labels to be displayed in the backend module. |
| 61 | + |
| 62 | +Line 4 sets the category. |
| 63 | + |
| 64 | +Line 5 sets the type. See all available types here: |
| 65 | +`Site setting definition types <https://docs.typo3.org/permalink/t3coreapi:definition-types>`_. |
| 66 | + |
| 67 | +Line 6 defines a default. If you define a default its type in YAML |
| 68 | +**has to match** the type defined in line 5. |
| 69 | + |
| 70 | +All properties that can be defined for setting definitions can be found here: |
| 71 | +`Site setting definition properties <https://docs.typo3.org/permalink/t3coreapi:site-settings-definition-properties>`_. |
| 72 | + |
| 73 | +.. seealso:: |
| 74 | + * `Site settings definitions <https://docs.typo3.org/permalink/t3coreapi:site-settings-definition>`_ |
| 75 | + * `Configuring the site settings editor <https://docs.typo3.org/permalink/t3coreapi:sitehandling-settings-editor-configuration>`_ |
| 76 | + * `Site management: Trouble shooting <https://docs.typo3.org/permalink/t3start:site-management-trouble>`_ |
| 77 | + |
| 78 | +.. _usage-settings-fluid: |
| 79 | + |
| 80 | +Using setting entries in a Fluid template |
| 81 | +========================================= |
| 82 | + |
| 83 | +The site settings are available as variable `{settings}` |
| 84 | +(see :ref:`settings <t3tsref:confval-pageview-data-settings>`) within the templates |
| 85 | +of the page as we as we are using the `PAGEVIEW <https://docs.typo3.org/permalink/t3tsref:cobj-pageview>`_ |
| 86 | +TypoScript object. |
| 87 | + |
| 88 | +In the site package example we display the logo once in the header in large and |
| 89 | +once in the footer in smaller and use the settings to determine the path and alt |
| 90 | +text in both cases: |
| 91 | + |
| 92 | +.. literalinclude:: /CodeSnippets/my_site_package/Resources/Private/PageView/Partials/Footer.html |
| 93 | + :caption: packages/my_site_package/Resources/Private/PageView/Partials/Footer.html |
| 94 | + |
| 95 | +At the time of writing the settings are not available out-of-the-box in |
| 96 | +templates configured by `FLUIDTEMPLATE <https://docs.typo3.org/permalink/t3tsref:cobj-template>`_ |
| 97 | +objects, for example in |
| 98 | +`custom content element templates <https://docs.typo3.org/permalink/t3sitepackage:content-element-rendering>`_ |
| 99 | +or within `Custom Content Blocks <https://docs.typo3.org/permalink/t3sitepackage:content-blocks>`_. |
| 100 | +You would have to supply them with a `Custom data processor <https://docs.typo3.org/permalink/t3tsref:customdataprocessors>`_. |
| 101 | + |
| 102 | +.. _usage-settings-typoscript: |
| 103 | + |
| 104 | +Using settings in TypoScript |
| 105 | +============================ |
| 106 | + |
| 107 | +In both frontend TypoScript and backend TypoScript, also called TSconfig, the |
| 108 | +settings can be used with the |
| 109 | +`TypoScript constants syntax <https://docs.typo3.org/permalink/t3tsref:typoscript-syntax-using-constants>`_. |
| 110 | + |
| 111 | +In the site package example we use constants to configure the path to the |
| 112 | +favicon and templates (both of type `string`): |
| 113 | + |
| 114 | +.. literalinclude:: /CodeSnippets/my_site_package/Configuration/Sets/SitePackage/TypoScript/page.typoscript |
| 115 | + :caption: packages/my_site_package/Configuration/Sets/SitePackage/TypoScript/page.typoscript |
| 116 | + |
| 117 | +And in the footer menu we use a setting of type `int` to set the root folder in |
| 118 | +which the pages for the footer menu are found: |
| 119 | + |
| 120 | +.. literalinclude:: /CodeSnippets/my_site_package/Configuration/Sets/SitePackage/TypoScript/Navigation/footerMenu.typoscript |
| 121 | + :caption: packages/my_site_package/Configuration/Sets/SitePackage/TypoScript/Navigation/footerMenu.typoscript |
| 122 | + |
| 123 | +It is also possible to use settings in TypoScript conditions: |
| 124 | +`Check if a setting/constant is set to a certain value <https://docs.typo3.org/permalink/t3tsref:condition-examples-constant>`_. |
0 commit comments