Skip to content

Commit

Permalink
#9 Added UndefinedVariableException
Browse files Browse the repository at this point in the history
- Added Documentation
  • Loading branch information
matthes committed May 8, 2018
1 parent c9fb746 commit 4447c4b
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,17 @@ Hello World
{/if}
```

Shortcut: Test if a variable is null:

```
{if someVarName}
someVarName is set!
{/if}
{if !someVarName}
someVarName is not set!
{/if}
```

Limitation: Logical connections like OR / AND are not possible at the moment. Maybe in the future.

## Conditions (else)
Expand Down Expand Up @@ -258,6 +269,28 @@ To see all Parameters passed to the template use:
It will output the structure of the current context.


## Dealing with undefined Variables

By default text-template will not throw any exceptions when a template
tries to access an undefined variable.

To improve debugging, you can switch this behaviour by setting `$softFail` to
`false` (Parameter 2 of `apply()` function):

```php
try {
$tt = new TextTemplate("{=someUndefinedName}");
$parser->apply([], false);
// ^^^^^
} catch (UndefinedVariableExceptions $e) {
echo "UndefinedVariable: {$e->getTriggerVarName()}"
}
```
will return
```
UndefinedVariable: someUndefinedName
```

## Limitations

The logic-Expression-Parser won't handle logic connections (OR / AND) in conditions.
Expand Down

0 comments on commit 4447c4b

Please sign in to comment.