7
7
Constants
8
8
=========
9
9
10
- .. include :: /Images/AutomaticScreenshots/TemplatesModul/TemplatesConstants.rst.txt
10
+ .. versionchanged :: 12.0
11
+ The TypoScript management tools are now found in backend module
12
+ :guilabel: `Site Management > TypoScript `. It was formerly found in
13
+ "Page > Template".
14
+
15
+ .. figure :: /Images/ManualScreenshots/TypoScriptModule/ConstantEditor.png
16
+ :alt: Screenshot of the TYPO3 Backend showing the constant editor
17
+
18
+ The :ref: `Constant Editor <constant-editor>` in the TYPO3 backend
11
19
12
20
Constants are values defined in the :guilabel: `Constants ` field of a template. They
13
21
follow the :ref: `syntax of ordinary TypoScript
14
22
<t3coreapi:typoscript-syntax-syntax>` and are case sensitive! They are used to
15
23
manage *in a single place * values, which are later used in *several places *.
16
24
25
+ .. seealso ::
26
+ Most constants can be edited in the :guilabel: `Template ` module using the
27
+ :guilabel: `Constant Editor `.
28
+
29
+ If you keep your constants in a site package extension you can also make
30
+ them :ref: `available for the Constant Editor <typoscript-syntax-constant-editor >`.
31
+
17
32
.. index :: Constants; Definition
33
+ .. _typoscript-syntax-constants-definition :
18
34
19
35
Defining constants
20
36
==================
@@ -35,6 +51,7 @@ Constants do not support multiline values!
35
51
You can use environment variables to provide instance specific values to your constants.
36
52
Refer to :ref: `getEnv <getenv >` for further information.
37
53
54
+ .. _typoscript-syntax-constants-definition-example :
38
55
39
56
Example
40
57
-------
@@ -49,11 +66,11 @@ expected location.
49
66
50
67
bgCol = red
51
68
file {
52
- toplogo = fileadmin/logo.gif
69
+ toplogo = fileadmin/logo.gif
53
70
}
54
71
topimg {
55
- width = 200
56
- file.pic2 = fileadmin/logo2.gif
72
+ width = 200
73
+ file.pic2 = fileadmin/logo2.gif
57
74
}
58
75
59
76
The objects in the highlighted lines contain the reserved word "file" and the
@@ -78,55 +95,69 @@ one would perform any ordinary string replacement. Constants are used in the
78
95
{$topimg.file.pic2}
79
96
{$file.toplogo}
80
97
81
- Only constants, which are actually defined in the :guilabel: `Constants ` field, are
98
+ Only constants, which are actually defined in the :guilabel: `Constants ` field
99
+ or an included :file: `constants.typoscript ` file, are
82
100
substituted.
83
101
84
- Constants in included templates are also substituted, as the whole
85
- template is one large chunk of text .
102
+ Constants from included TypoScript files are also substituted. All TypoScript
103
+ constants are combined before the TypoScript Setup configuration is resolved .
86
104
87
105
A systematic naming scheme should be used for constants. As "paths" can be
88
106
defined, it's also possible to structure constants and prefix them with a common
89
107
path segment. This makes reading and finding of constants easier.
90
108
109
+ .. _typoscript-syntax-using-constants-example :
110
+
91
111
Example
92
112
-------
93
113
94
114
.. code-block :: typoscript
115
+ :caption: EXT:my_sitepackage/Configuration/TypoScript/setup.typoscript
95
116
96
117
page = PAGE
97
118
page {
98
- typeNum = 0
99
- bodyTag = <body bgColor ="{$bgCol}">
100
- 10 = IMAGE
101
- 10.file = {$file.toplogo}
119
+ typeNum = 0
120
+ bodyTag = <body class ="{$tx_my_sitepackage. bgCol}">
121
+ 10 = IMAGE
122
+ 10.file = {$tx_my_sitepackage. file.toplogo}
102
123
}
103
124
104
125
For the above example to work, the constants from the last example have to be
105
- defined in the constants field.
126
+ defined in the constants field or a file called :file: ` constants.typoscript `:
106
127
107
- .. include :: /Images/AutomaticScreenshots/TemplatesModul/TemplatesSetup.rst.txt
128
+ .. code-block :: typoscript
129
+ :caption: EXT:my_sitepackage/Configuration/TypoScript/constants.typoscript
108
130
109
- Constants in the setup code are substituted, marked in green. In the Object
110
- Browser, it's possible to show constants substituted and unsubstituted.
131
+ tx_my_sitepackage {
132
+ bgCol = bg-primary
133
+ file.toplogo = EXT:my_sitepackage/Resources/Public/Images/Logo.png
134
+ }
111
135
112
- The "Display constants" function is not available if "Crop lines" is selected.
136
+ .. figure :: /Images/ManualScreenshots/TypoScriptModule/ConstantAndSetupRecord.png
137
+ :alt: Screenshot of the TypoScript record editor showing the Constants and Setup fields
113
138
114
- .. note ::
139
+ The fields :guilabel: `Constants` and :guilabel:`Setup` in the TypoScript backend record
115
140
116
- The TypoScript constants are evaluated in this order:
141
+ You can use the sub module :guilabel: `Site Management > TypoScript > Active TypoScript `
142
+ to display how constants are replaced. The constant key is displayed in red, the
143
+ replacement in green:
117
144
118
- #. :php: `$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_constants'] `
119
- via :php: `\T YPO3\C MS\C ore\U tility\E xtensionManagementUtility::addTypoScriptConstants() `
120
- #. Site specific :ref: `settings from the site configuration <t3coreapi:sitehandling >`
121
- #. Constants from :sql: `sys_template ` database records
145
+ .. figure :: /Images/ManualScreenshots/TypoScriptModule/ConstantsInActiveTypoScript.png
146
+ :alt: Screenshot of the Active TypoScript with constants substituted
122
147
148
+ .. versionchanged :: 12.0
149
+ The TypoScript management tools are now found in backend module
150
+ :guilabel: `Site Management > TypoScript `. It was formerly found in
151
+ "Page > Template".
123
152
124
- The constant editor
125
- ===================
153
+ The submodule :guilabel: ` Active TypoScript ` was renamed from
154
+ "TypoScript Object Browser".
126
155
127
- Most constants can be edited in the :guilabel: `Template ` module using the :guilabel: `constant editor `.
128
- If you keep your constants in a sitepackage extension you can also make them :ref: `available for the
129
- constant editor <typoscript-syntax-constant-editor>`.
156
+ .. note ::
130
157
131
- .. include :: /Images/AutomaticScreenshots/TemplatesModul/TemplatesConstantEditor.rst.txt
158
+ The TypoScript constants are evaluated in this order:
132
159
160
+ #. :php: `$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_constants'] `
161
+ via :php: `\T YPO3\C MS\C ore\U tility\E xtensionManagementUtility::addTypoScriptConstants() `
162
+ #. Site specific :ref: `settings from the site configuration <t3coreapi:sitehandling >`
163
+ #. Constants from :sql: `sys_template ` database records
0 commit comments