Using a condition to check values
In some cases you need to display or hide content based on some condition. This can easily be done by putting the content into a condition block. Then you check the value of a so-called flag, i.e. variables with a value of either 0 (off/no/false) or 1 (on/yes/true) in the condition.
Suppose you want to display a text only if the variable show_content is true (has a value greater than zero). In the CONSTANTS field of your TypoScript template you just define a variable and set it to a default value (here: 1).
TypoScript: Define a variable
# Set variable 'show-content' to a default value of 1 show_content = 1
TypoScript: Check a variable in a condition
temp.some_text = TEXT [globalVar = LIT:0<{$show_content}] # Assign a string to the text object, if condition is true temp.some_text.value = The variable is greater than zero [else] # Empty text object, if condition is false temp.some_text > [global]
The condition checks, if our variable show_content is greater than the (literal, LIT in TypoScript) value 0 (zero). If this condition is true - which is the default in our example - the text object is filled with content. Otherwise (the 'else' case), the text object is emptied.
Remember that such conditions generally have to be written outside of any statement blocks (i.e. outside of curly brackets)!
Please do also read our Best Practice article about constants in TypoScript.
Read on
Visitors found this page by searching for these keywords: