[solved] Question about conditions

Hi,

I am using TYPO3 9.5.23 and I wonder why this doesn’t work:

[applicationContext == "Production"]
  page = PAGE
  page.10 = TEXT
  page.10.value = Hier entsteht eine neue Homepage
[end]
[applicationContext == "Development"][applicationContext == "Testing"]
  @import 'fileadmin/page/Configuration/TypoScript/*.setup.ts'
[end]

If I switch the order of the two conditions the message is shown but the setup files load as well. The first condition “[applicationContext = Production*]” seems to work well, but the second condition doesn’t seem to have any effect at all. The statement is executed anyways.

Changing the 2nd condition to this doesn’t work either:

[applicationContext == "Development"]
  @import 'fileadmin/page/Configuration/TypoScript/*.setup.ts'
[end]
[applicationContext == "Testing"]
  @import 'fileadmin/page/Configuration/TypoScript/*.setup.ts'
[end]

Best regards

edit: trying to fix the code-formatting
edit2: weird, seeems as if the @import statements are executed no matter what the conditions are.

Dear nils, in TYPO3 Version 9, there are two possibilities for conditions:

old syntax:

applicationContext is “Production”

[applicationContext = Production*]

new:
[applicationContext == “Production”]

See https://docs.typo3.org/m/typo3/reference-typoscript/9.5/en-us/Conditions/Index.html#upgrading

I guess you used the new syntax for version 10, which is only available in V9 if you activate it.

Hello Stefan,

thank you very much for the quick reply.

This is strange, I don’t remeber activating the new syntax. However the condition “[applicationContext == “Production”]” is working fine. By the way: I’ve already tried the other syntax too and it didn’t change a thing.

Right now I am working around the problem with this at the end of my setup to erase all the previous changes:

[applicationContext == "Production"]
  page = PAGE
  page.10 = TEXT
  page.10.value = Hier entsteht eine neue Homepage
  page.includeCSS >
[end]

This works for now but I am still wondering:

# example 1
[applicationContext == "Testing"]
  @import 'fileadmin/page/Configuration/TypoScript/*.setup.ts'
[end]
# example 2
[applicationContext = Testing*]
  @import 'fileadmin/page/Configuration/TypoScript/*.setup.ts'
[end]
# example 3
@import 'fileadmin/page/Configuration/TypoScript/*.setup.ts'

All 3 examples do exactly the same no matter what the applicationContext is.

Regards

I might be wrong here, but it could be related to the processing order of typoscript.

From the developers point of view it would totally make sense to process inclusion non-sequentially (in some kind of pre-processing). Conditions however could depend on the evaluation of variables, so you might want to evaluate them in the sequential order of the script. Maybe that was the reason why the old include statement offered a condition parameter.

edit: fixed typos and added detail

If my previous assumption were true, it still shouldn’t cancel out the condition around the included code. The fact that I am using conditions inside those included files could be the real problem.

Does typoscript allow nested conditions?

Ok, I am pretty sure it’s the combination of the processing order and the nested conditions.

fileadmin/testfile.ts:

page.30 = TEXT
page.30.value = 30: Before inner condition (true).<br />
# always true condition
[1 == 1]
  page.40 = TEXT
  page.40.value = 40: Inside inner condition.<br />
[end]
page.50 = TEXT
page.50.value = 50: After inner condition (true).<br />

page ts setup:

page = PAGE
page.10 = TEXT
page.10.value = 10: Before outer condition (false)<br />
# always false condition
[0 == 1]
  page.20 = TEXT
  page.20.value = 20: Before include<br />
  @import 'fileadmin/testfile.ts'
  page.60 = TEXT
  page.60.value = 60: After include<br />
[end]
page.70 = TEXT
page.70.value = 70: After outer condition (false)<br />

I’ve got this result:

10: Before outer condition (false)
40: Inside inner condition.
50: After inner condition (true).
60: After include
70: After outer condition (false)

It seems as if the @import statement is treaded like some kind of preprocessor statement and is processed before the evaluation of the script, disregarding the state of the condition. The condition inside the imported file cancels out the previous condition then.

In hindsight i have to add that it just seemed that way because the included files started with a condition.