aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/smarty/smarty/docs/designers/language-builtin-functions/language-function-shortform-assign.md
blob: d6a9e979898f2aa992f40e9533ad9e0c9cc3c52f (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
{\$var=\...} {#language.function.shortform.assign}
============

This is a short-hand version of the {assign} function. You can assign
values directly to the template, or assign values to array elements too.

> **Note**
>
> Assignment of variables in-template is essentially placing application
> logic into the presentation that may be better handled in PHP. Use at
> your own discretion.

The following attributes can be added to the tag:

**Attributes:**

   Attribute Name   Shorthand    Type    Required   Default  Description
  ---------------- ----------- -------- ---------- --------- -----------------------------------------------------------------------
       scope           n/a      string      No       *n/a*   The scope of the assigned variable: \'parent\',\'root\' or \'global\'

**Option Flags:**

    Name    Description
  --------- -----------------------------------------------------
   nocache  Assigns the variable with the \'nocache\' attribute


    {$name='Bob'}

    The value of $name is {$name}.

      

The above example will output:


    The value of $name is Bob.

      


    {$running_total=$running_total+$some_array[row].some_value}

      


    {$user.name="Bob"}

      


    {$user.name.first="Bob"}

      


    {$users[]="Bob"}

      

Variables assigned in the included template will be seen in the
including template.


    {include file="sub_template.tpl"}
    ...
    {* display variable assigned in sub_template *}
    {$foo}<br>
    ...

      

The template above includes the example `sub_template.tpl` below


    ...
    {* foo will be known also in the including template *}
    {$foo="something" scope=parent}
    {* bar is assigned only local in the including template *}
    {$bar="value"}
    ...

See also [`{assign}`](#language.function.assign) and
[`{append}`](#language.function.append)