Twig Components / Available variables in Twig
To see all variables defined in the current page, use
App¶
App is an instance of Symfony\Bridge\Twig\Appvariable
. It contains:
Name | Description |
---|---|
debug |
Boolean indicating whether Debug is enabled or not |
environment |
Indicating the current environment, like dev or prod |
request |
Instance of Symfony\Component\HttpFoundation\Request |
session |
Instance of Symfony\Component\HttpFoundation\Session\Session |
flashes |
Array of Session Flashes |
user |
Instance of Bolt\Entity\User |
tokenStorage |
Instance of Symfony's UsageTrackingTokenStorage |
requestStack |
Instance of Symfony\Component\HttpFoundation\RequestStack |
Request¶
The app variable also includes information about the request, accessible by:
Session¶
The session can be accessed through the app variable:
User¶
Apart from the global user
variable, the user can also be accessed using the
app variable:
Environment¶
The current environment, as set in your .env
file, can be accessed:
For more info on app
, check the Symfony app variable.
Flashes¶
Symfony's flashes can be accessed through the global app variable:
Config¶
The config global variable is used to access the configuration available in
your config.yaml
and contenttypes.yaml
files. It has a bunch of useful
methods
get(path)¶
Returns a config value using a path
has(path)¶
Returns true if config matches path, and false otherwise.
contentType(contenttype)¶
Returns the configuration for the given contenttype.
Theme¶
The global theme variable contains the configuration for your current theme, as
defined in theme.yaml
. For example, if you have configured your theme with a
dark/light modes, here is how to access them:
Note: Unlike the global config
,
the global theme
variable is a multi-dimensional array. Thus,
to access nested configurations, use theme.get('level-1').get('level-2')
.
Record¶
Most pages will have a global 'record' defined that corresponds to the current page. For more information on this, see Record and Records
Couldn't find what you were looking for? We are happy to help you in the forum, on Slack or on Github.