Today I struggled with a problem concerning TypoScript conditions and included files.

‪I'm wrestling with TYPO3 for about 16 years now, and yet sometimes the most basic stuff trips me, like accidently creating nested conditions by including TypoScript files inside a condition‬.

In a setup.typoscript file I had several includes, and additionally I wanted to include an (temporarly) override file only for me, behind the Dev-IP. It was a hack to emulate a test environment without the need to duplicate the site. To make things more interesting, this was in an old 7.6 install, and I somehow forgot that nested conditions aren't possible in old TypoScript.

This is the basic concept:

```
this will be visible for everyone
[IP = 123.123.123.123]
show someting only if the IP matches
[END]
show this for everyone
```

This is all good and works.
For maintenance reasons I bundled a bunch of TypoScript overrides in a file "overrides.setup.typoscript" and include that in my main "setup.typoscript", inside a condition check against my IP address:

```
this will be visible for everyone
[IP = 123.123.123.123]
<include_typoscript: source="FILE:EXT:my_ext/Configuration/TypoScript/overrides.setup.typoscript"></include_typoscript:>
[END]
show this for everyone
```

Surprisingly for me (and the client involved), some of the changes I modified in this override file were visible for all in the front end. Wtf.

On a first hunch I thought maybe it isn't possible to include TypoScript files _inside_ a condition, so I moved the condition inside the override file.

Only then did I notice that I had defined another condition for a section of the code that only should be applied on the root page in that file:

```
some stuff
[treeLevel = 0]
show this only on root page
[END]
other stuff
```

Now the complete TypoScript looks like this if the included file is honored:

```
this will be visible for everyone
[IP = 123.123.123.123]
some stuff
[treeLevel = 0]
show this only on root page
[END]
other stuff
[END]
show this for everyone
```

As you can see, and knowing that nested conditions are not a thing in TypoScript at that time, the inner "end" will terminate the IP-condition, and "other stuff" will be globally visible, even if it is in the file that was intended to show only stuff behind that IP. The second "end" has no effect, maybe it'll throw a warning in the TypoScript explorer in the backend, I haven't checked yet. D'oh.

So what is needed is this:

```
this will be visible for everyone
[IP = 123.123.123.123]
some stuff
[END]
[IP = 123.123.123.123] && [treeLevel = 0]
show this only on root page
[end]
[IP = 123.123.123.123]
other stuff
[END]
show this for everyone
```

And this'll work.
So be careful when including TypoScript files conditionally - I'd say don't do this at all and instead make conditions only inside files, not "around" the include, since this will very likely break upon some conditions that are already in the file.

If you add the surrounding condition inside the file at least you have a chance to spot the incorrect nesting.

Thanks to Joschi (@jkphl), who once again kindly acted as my rubber duck; while explaining what I was trying to do, the error materialized.