aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/smarty/smarty/docs/designers/language-modifiers/language-modifier-default.md
blob: ce08e96ef8b42bc9f1e07b651d648a76952f686c (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
default {#language.modifier.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.

   Parameter Position    Type    Required   Default  Description
  -------------------- -------- ---------- --------- ---------------------------------------------------------------
           1            string      No      *empty*  This is the default value to output if the variable is empty.


    <?php

    $smarty->assign('articleTitle', 'Dealers Will Hear Car Talk at Noon.');
    $smarty->assign('email', '');

    ?>

       

Where template is:


    {$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](#tips.default.var.handling) and
the [blank variable handling](#tips.blank.var.handling) pages.