Working around nested conditions in TypoScript

As you may know, nested conditions are not supported in TypoScript, nor is negating a condition. This can be really painful at times, so here is my way to workaround that problem. Unfortunately, it is not applicable to all situations, so if you’ve know of a better way to do this, please leave a comment :)

Negations can be expressed in TypoScript using the following workaround:

[PIDInRootLine = 42]
    # Does nothing
[else]
    # So this is ![PIDInRootLine = 42]
[end]

Not very elegant, I know. Also, this doesn’t work if you want to negate only a single condition of an expression, for example:

[PIDInRootLine = 42] && [usergroup = *]
    # Does nothing
[else]
    # This is !([PIDInRootLine = 42] && [usergroup = *])
[end]

But what if we want this:

[PIDInRootLine = 42] && ![usergroup = *]

I’ve worked around this limitation by writing two conditions based on the fact that, when I write a condition such as the former, I want to express something like “Do something if A and if not B”, which also can be expressed as “Do something if A. Then, if B, undo what you did.”. According to this translation, the former expression could be written like this:

page.10 = TEXT
page.10.value = 100

tempValue < page.10.value
[PIDInRootLine = 42]
    page.10.value = 42
[end]

[usergroup = *]
    page.10.value < tempValue
[end]

This changes page.10.value to 42, but only if [PIDInRootLine = 42] && ![usergroup = *]. Not very elegant either, but it did solve my problem and I hope it helps you solve yours too :)

Bash Prompt Generator

I wrote a little JavaScript tool to generate fancy Bash Prompts for your favorite UNIX OS. It is still a WIP, but the basic functionality is there.

You can check it out here, and the source-code is hosted on GitHub.

Please let me know what you think of it, any suggestion are welcome :)

New Old Theme

I switched back to the Twenty-Eleven Theme, because Platform, which I had installed before, was really annoying to customize and there were some incompatibilities with the Code-Colorer Plugin (which is really great, by the way). I find this one much better to read anyway.

Let me know what you think :)

Proper redirecting in TYPO3 (from within PHP)

Redirecting in PHP is easy:

$url = "http://coding-journal.com/";
header("Location: $url");

But there is tons of stuff to worry about when doing a header redirect, for instance:

  • What HTTP status will be sent?
  • Is the URL I’m throwing into the header-call really absolute?
  • Does my script exit after the header-call? (Because there should be no HTTP body if you send a Location: ... header and sending one may lead to unexpected behavior in some browsers).

    Continue reading

Keeping track of foreign codebase modifications with Git

I’ve been there a lot: I’m using some kind of existing framework / tool / open source software which is awesome, but there is that tiny little thing that annoys me, and I’d like to change it.

Continue reading