ternary operator

Drupal 8 Twig ternary operator syntax

As a quick note, the Drupal 8 Twig template ternary operator syntax looks like this:

{{ foo ? 'FOO IS TRUE' : 'FOO NOT TRUE' }}

You can test it like this in a Drupal 8 Twig template theme file if you’d like:

{% set foo = true %}
{{ foo ? 'FOO IS TRUE' : 'FOO NOT TRUE' }}

That test will emit the string “FOO IS TRUE” to your web browser.

You can find more Twig information at this symfony.com page.

The Scala ternary operator syntax

Scala FAQ: What is the Scala ternary operator syntax?

In other programming languages there is a definite, unique ternary operator syntax, but in Scala, the ternary operator is just the normal Scala if/else syntax:

if (i == 1) x else y

The beauty of this is (a) it is just the normal if/else syntax, so you don't have to remember something else, and (b) it's easy to read.