Bug #103953
closed
Site config settings can't be used in TypoScript conditions anymore
Added by Philipp Kitzberger 6 months ago.
Updated 5 months ago.
Description
TypoScript conditions generally support the usage of constants.
But with the refactoring of the TypoScript parser in version 12 site constants cannot be used anymore!
How to reproduce:
- Add a constant to a site's
settings.yaml
file
- Create a condition based on it
[{$foo} == 'bar']
page.20 = TEXT
page.20.value = the site constant "foo" is "bar"
[global]
For a constant set in regular TypoScript constant files or sys_template
records it's still working though.
Files
- Related to Bug #103364: Site config settings can't be used to override constants anymore added
- Related to Bug #102452: TypoScript constants from site settings are not substituted in Backend Extbase Modules added
Just found out that accessing that same constant via the site configuration is a working workaround:
[traverse(site("configuration"), "settings/foo") == "bar"]
tl;dr:
broken:
[{$foo} == 'bar']
working:
['{$foo}' == 'bar']
Long story: I played around on this in v12 again:
- Go to TypoScript BE module "Included TypoScript".
- Look at the "Constants" "Configuration" tree and see there is a node "Site constants settings of site "..."". Clicking the {} button should show you the 'constant' foo being set to bar -> the site setting is turned into a constant.
- See the condition being listed in the "condition" section, with its value being updated to bar. See screenshot, too.
- Call FE and see condition kicks in.
- Change the constant value in settings.yaml from 'bar' to 'baz', and see the condition no longer kicks in in FE and [else] branch is rendered.
Your example above uses
[{$foo} == 'bar']
, but it should be
['{$foo}' == 'bar']
. I rechecked this in v11, and the condition does not work in v11 with the missing ticks, either, but does works if the constant is surrounded by ticks.
-> Using site settings as constants in conditions does work, imho. Could you recheck, please?
- Status changed from New to Needs Feedback
Using site settings as constants in conditions does work, imho. Could you recheck, please?
Yes, your workaround (wrapping the constant in quotes) does work in setup conditions, but not in constant conditions. The latter is probably due to the fact that constants are not being resolved recursively anymore, right?
My workaround is working in both setup and constant conditions:
[traverse(site("configuration"), "settings/foo") == "bar"]
- Status changed from Needs Feedback to New
I see. Yes. Accessing constants does not work within constants at all, and as such, not in constant conditions, either.
We may want to clarify this in the docs.
- Status changed from New to Under Review
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
- Status changed from Resolved to Closed
Also available in: Atom
PDF