Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

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