# Conditional Statements Brace supports block-level `{{ if }}` statements and compact in-line conditions. --- ## `if` block ``` {{ if first_name EXISTS }}

Hello {{ first_name }}

{{ end }} ``` --- ## `if … else` ``` {{ if first_name EXISTS }} Hello {{ first_name }} {{ last_name }} {{ else }} Name does not exist {{ end }} ``` --- ## `if … elseif … else` Multiple branches can be chained with `{{ elseif }}`. ``` {{ if name->first && name->last }} Hello {{ name->first }} {{ name->last }} {{ elseif name->first }} Hello {{ name->first }} {{ elseif name->last }} Hello Mr {{ name->last }} {{ else }} Name does not exist {{ end }} ``` --- ## Conditions inside iterators Conditions work inside `{{ each }}` blocks and have access to the iteration variables. ``` {{ each names as name }} {{ if _ITERATION === "is_first_item" }} {{ name }} {{ elseif _ITERATION === "is_last_item" }} {{ name }} {{ elseif _ITERATION == 2 }} {{ name }} {{ else }} {{ name }} {{ end }} {{ end }} ``` --- ## AND / OR conditions Combine multiple conditions with `&&` (AND) and `||` (OR). ``` {{ if first_name EXISTS && first_name == "John" }}

My first name is {{ first_name }}

{{ else }}

Please enter your first name

{{ end }} ``` ``` {{ if role == "admin" || role == "editor" }}

You have write access

{{ end }} ``` --- ## In-line conditions In-line conditions are written inside double braces `{{ }}` and produce a string result directly. ### Syntax ``` {{ condition ? "true output" : "false output" }} {{ condition ? "true output" }} ``` Placeholders in the output string use `__variable__` syntax (double underscores). ### EXISTS check ```php parseInputString( '{{ name EXISTS ? "Hello __name__" : "No name" }}', ['name' => 'Alice'], false )->return(); // Output: Hello Alice ``` ### Comparison ```php echo $brace->parseInputString( '{{ first_name !== "test" ? "__first_name__" : "is test" }}', ['first_name' => 'John'], false )->return(); // Output: John ``` ### Escaping quotes in the output ```php echo $brace->parseInputString( '{{ first_name !== "test" ? "Name is \"__first_name__\"" }}', ['first_name' => 'John'], false )->return(); // Output: Name is "John" ``` ### AND / OR in in-line conditions ```php // AND echo $brace->parseInputString( '{{ name EXISTS && age >= 21 ? "Welcome __name__, you are __age__" }}', ['name' => 'Simon', 'age' => 21], false )->return(); // Output: Welcome Simon, you are 21 // OR echo $brace->parseInputString( '{{ name === "Dave" || name === "Simon" ? "Hello __name__" : "Stranger" }}', ['name' => 'Simon'], false )->return(); // Output: Hello Simon ``` --- ## Conditions reference | Operator | Description | |-----------|----------------------------------------------------------| | `==` | Equal (loose comparison) | | `===` | Identical (strict comparison) | | `!=` | Not equal (loose comparison) | | `!!` | Not identical (strict non-equality comparison) | | `!==` | Not identical — alias for `!!`, identical behaviour | | `>` | Greater than | | `<` | Less than | | `>=` | Greater than or equal to | | `<=` | Less than or equal to | | `EXISTS` | Variable exists and is non-empty | | `!EXISTS` | Variable does not exist or is empty |