aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/smarty/smarty/docs/designers/language-builtin-functions/language-function-config-load.md
blob: 750f337c489a6906e40c04ce3788852e7dc8ac20 (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
85
86
87
88
89
90
91
{config\_load} {#language.function.config.load}
==============

`{config_load}` is used for loading config
[`#variables#`](#language.config.variables) from a [configuration
file](#config.files) into the template.

**Attributes:**

   Attribute Name    Type    Required   Default  Description
  ---------------- -------- ---------- --------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
        file        string     Yes       *n/a*   The name of the config file to include
      section       string      No       *n/a*   The name of the section to load
       scope        string      no      *local*  How the scope of the loaded variables are treated, which must be one of local, parent or global. local means variables are loaded into the local template context. parent means variables are loaded into both the local context and the parent template that called it. global means variables are available to all templates.

The `example.conf` file.


    #this is config file comment

    # global variables
    pageTitle = "Main Menu"
    bodyBgColor = #000000
    tableBgColor = #000000
    rowBgColor = #00ff00

    #customer variables section
    [Customer]
    pageTitle = "Customer Info"

      

and the template


    {config_load file="example.conf"}
    {config_load "example.conf"}  {* short-hand *}

    <html>
    <title>{#pageTitle#|default:"No title"}</title>
    <body bgcolor="{#bodyBgColor#}">
    <table border="{#tableBorderSize#}" bgcolor="{#tableBgColor#}">
       <tr bgcolor="{#rowBgColor#}">
          <td>First</td>
          <td>Last</td>
          <td>Address</td>
       </tr>
    </table>
    </body>
    </html>

      

[Config Files](#config.files) may also contain sections. You can load
variables from within a section with the added attribute `section`. Note
that global config variables are always loaded along with section
variables, and same-named section variables overwrite the globals.

> **Note**
>
> Config file *sections* and the built-in template function called
> [`{section}`](#language.function.section) have nothing to do with each
> other, they just happen to share a common naming convention.


    {config_load file='example.conf' section='Customer'}
    {config_load 'example.conf' 'Customer'} {* short-hand *}

    <html>
    <title>{#pageTitle#}</title>
    <body bgcolor="{#bodyBgColor#}">
    <table border="{#tableBorderSize#}" bgcolor="{#tableBgColor#}">
       <tr bgcolor="{#rowBgColor#}">
          <td>First</td>
          <td>Last</td>
          <td>Address</td>
       </tr>
    </table>
    </body>
    </html>

      

See [`$config_overwrite`](#variable.config.overwrite) to create arrays
of config file variables.

See also the [config files](#config.files) page, [config
variables](#language.config.variables) page,
[`$config_dir`](#variable.config.dir),
[`getConfigVars()`](#api.get.config.vars) and
[`configLoad()`](#api.config.load).