---
title: "Constants"
manual: "TypoScript Explained"
version: "13.4"
permalink: "https://docs.typo3.org/permalink/t3tsref:typoscript-syntax-constants@13.4"
source: "UsingSetting/Constants.rst"
rendered: "2026-09-18T10:44:33+00:00"
---

# Constants {#typoscript-syntax-constants}

![Screenshot of the TYPO3 Backend showing the constant editor](../Images/ManualScreenshots/TypoScriptModule/ConstantEditor.png)

Constants are values defined in the **Constants** field of a template.  They
follow the [syntax of ordinary TypoScript](https://docs.typo3.org/permalink/t3tsref:typoscript-syntax@13.4) and are case sensitive! They are used to
manage *in a single place* values, which are later used in *several places*.

> [!NOTE]
> **See also**
>
> Most constants can be assigned in the **TypoScript** module using the
> **Constant Editor**.
>
> If you keep your constants in a site package extension you can also make
> them [available for the Constant Editor](https://docs.typo3.org/permalink/t3tsref:typoscript-syntax-constant-editor@13.4).

## Defining constants {#typoscript-syntax-constants-definition}

Other than constants in programming languages, values of constants in TypoScript
can be overwritten. Constants in TypoScript can more be seen as variables in
programming languages.

**Reserved name**

The object or property "file" is always interpreted as data type [resource](https://docs.typo3.org/permalink/t3tsref:data-type-resource@13.4). That means it refers to a file, which has to be uploaded
in the TYPO3 CMS installation.

**Multi-line values: The ( ) signs**

Constants do not support multiline values!

You can use environment variables to provide instance specific values to your constants.
Refer to [getEnv](https://docs.typo3.org/permalink/t3tsref:getenv@13.4) for further information.

### Example {#typoscript-syntax-constants-definition-example}

Here `bgCol` is set to "red", `file.toplogo` is set to
`fileadmin/logo.gif` and `topimg.file.pic2` is set to
`fileadmin/logo2.gif`, assuming these files are indeed available at the
expected location.

**EXT:site_package/Configuration/Sets/Main/constants.typoscript**

```typoscript
bgCol = red
file {
  toplogo = fileadmin/logo.gif
}
topimg {
  width = 200
  file.pic2 = fileadmin/logo2.gif
}

```

The objects in the highlighted lines contain the reserved word "file" and the
properties are always of data type "[resource](https://docs.typo3.org/permalink/t3tsref:data-type-resource@13.4)".

## Using constants {#typoscript-syntax-using-constants}

When a TypoScript Template is parsed by the TYPO3 CMS, constants are replaced, as
one would perform any ordinary string replacement. Constants are used in the
"Setup" field by placing them inside curly braces and prepending them with a
`$` sign:

**EXT:site_package/Configuration/Sets/Main/setup.typoscript**

```typoscript
{$bgCol}
{$topimg.width}
{$topimg.file.pic2}
{$file.toplogo}

```

Only constants, which are actually defined in the **Constants** field
or an included `constants.typoscript` file, are
substituted.

Constants from included TypoScript files are also substituted. All TypoScript
constants are combined before the TypoScript Setup configuration is resolved.

A systematic naming scheme should be used for constants. As "paths" can be
defined, it's also possible to structure constants and prefix them with a common
path segment. This makes reading and finding of constants easier.

### Example {#typoscript-syntax-using-constants-example}

**EXT:my_sitepackage/Configuration/TypoScript/setup.typoscript**

```typoscript
page = PAGE
page {
  typeNum = 0
  bodyTag = <body class="{$tx_my_sitepackage.bgCol}">
  10 = IMAGE
  10.file = {$tx_my_sitepackage.file.toplogo}
}

```

For the above example to work, the constants from the last example have to be
defined in the constants field or a file called `constants.typoscript`:

**EXT:my_sitepackage/Configuration/TypoScript/constants.typoscript**

```typoscript
tx_my_sitepackage {
  bgCol = bg-primary
  file.toplogo = EXT:my_sitepackage/Resources/Public/Images/Logo.png
}

```

![Screenshot of the TypoScript record editor showing the Constants and Setup fields](../Images/ManualScreenshots/TypoScriptModule/ConstantAndSetupRecord.png)

You can use the sub module **Site Management > TypoScript > Active TypoScript**
to display which values are assigned to constants. The constant key is displayed in red, the
replacement in green:

![Screenshot of the Active TypoScript with constants substituted](../Images/ManualScreenshots/TypoScriptModule/ConstantsInActiveTypoScript.png)

> [!NOTE]
> The TypoScript constants are evaluated in this order:
>
> 1.  `$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_constants']`
>     via `\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTypoScriptConstants()`
> 1.  Site specific [settings from the site configuration](https://docs.typo3.org/m/typo3/reference-coreapi/13.4/en-us/ApiOverview/SiteHandling/Index.html#sitehandling)
> 1.  Constants from `sys_template` database records
