blob: b8697a0d9812bc74add5622cc12cc3296f73c383 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# default
This is used to set a default value for a variable. If the variable is
unset or an empty string, the given default value is printed instead.
Default takes the one argument.
## Basic usage
```smarty
{$myVar|default:"(none)"}
```
## Parameters
| Parameter | Type | Required | Default | Description |
|-----------|--------|----------|---------|---------------------------------------------------------------|
| 1 | string | No | *empty* | This is the default value to output if the variable is empty. |
## Examples
```php
<?php
$smarty->assign('articleTitle', 'Dealers Will Hear Car Talk at Noon.');
$smarty->assign('email', '');
```
Where template is:
```smarty
{$articleTitle|default:'no title'}
{$myTitle|default:'no title'}
{$email|default:'No email address available'}
```
Will output:
```
Dealers Will Hear Car Talk at Noon.
no title
No email address available
```
See also the [default variable handling](../../appendixes/tips.md#default-variable-handling) and
the [blank variable handling](../../appendixes/tips.md#blank-variable-handling) pages.
|