| 991 |
lars |
1 |
# Config Files
|
| 148 |
lars |
2 |
|
|
|
3 |
Config files are handy for designers to manage global template variables
|
|
|
4 |
from one file. One example is template colors. Normally if you wanted to
|
|
|
5 |
change the color scheme of an application, you would have to go through
|
|
|
6 |
each and every template file and change the colors. With a config file,
|
|
|
7 |
the colors can be kept in one place, and only one file needs to be
|
|
|
8 |
updated.
|
|
|
9 |
|
| 991 |
lars |
10 |
```ini
|
|
|
11 |
# global variables
|
|
|
12 |
pageTitle = "Main Menu"
|
|
|
13 |
bodyBgColor = #000000
|
|
|
14 |
tableBgColor = #000000
|
|
|
15 |
rowBgColor = #00ff00
|
| 148 |
lars |
16 |
|
| 991 |
lars |
17 |
[Customer]
|
|
|
18 |
pageTitle = "Customer Info"
|
| 148 |
lars |
19 |
|
| 991 |
lars |
20 |
[Login]
|
|
|
21 |
pageTitle = "Login"
|
|
|
22 |
focus = "username"
|
|
|
23 |
Intro = """This is a value that spans more
|
|
|
24 |
than one line. you must enclose
|
|
|
25 |
it in triple quotes."""
|
| 148 |
lars |
26 |
|
| 991 |
lars |
27 |
# hidden section
|
|
|
28 |
[.Database]
|
|
|
29 |
host=my.example.com
|
|
|
30 |
db=ADDRESSBOOK
|
|
|
31 |
user=php-user
|
|
|
32 |
pass=foobar
|
|
|
33 |
```
|
| 148 |
lars |
34 |
|
|
|
35 |
|
|
|
36 |
Values of [config file variables](./language-variables/language-config-variables.md) can be in
|
|
|
37 |
quotes, but not necessary. You can use either single or double quotes.
|
|
|
38 |
If you have a value that spans more than one line, enclose the entire
|
| 991 |
lars |
39 |
value with triple quotes \("""\). You can put comments into config
|
| 148 |
lars |
40 |
files by any syntax that is not a valid config file syntax. We recommend
|
| 991 |
lars |
41 |
using a `#` (hash) at the beginning of the line.
|
| 148 |
lars |
42 |
|
|
|
43 |
The example config file above has two sections. Section names are
|
|
|
44 |
enclosed in \[brackets\]. Section names can be arbitrary strings not
|
|
|
45 |
containing `[` or `]` symbols. The four variables at the top are global
|
|
|
46 |
variables, or variables not within a section. These variables are always
|
|
|
47 |
loaded from the config file. If a particular section is loaded, then the
|
|
|
48 |
global variables and the variables from that section are also loaded. If
|
|
|
49 |
a variable exists both as a global and in a section, the section
|
|
|
50 |
variable is used. If you name two variables the same within a section,
|
|
|
51 |
the last one will be used unless
|
|
|
52 |
[`$config_overwrite`](../programmers/api-variables/variable-config-overwrite.md) is disabled.
|
|
|
53 |
|
|
|
54 |
Config files are loaded into templates with the built-in template
|
| 991 |
lars |
55 |
function [`{config_load}`](./language-builtin-functions/language-function-config-load.md) or the API
|
| 148 |
lars |
56 |
[`configLoad()`](../programmers/api-functions/api-config-load.md) function.
|
|
|
57 |
|
|
|
58 |
You can hide variables or entire sections by prepending the variable
|
|
|
59 |
name or section name with a period(.) eg `[.hidden]`. This is useful if
|
|
|
60 |
your application reads the config files and gets sensitive data from
|
|
|
61 |
them that the template engine does not need. If you have third parties
|
|
|
62 |
doing template editing, you can be certain that they cannot read
|
|
|
63 |
sensitive data from the config file by loading it into the template.
|
|
|
64 |
|
|
|
65 |
Config files (or resources) are loaded by the same resource facilities
|
|
|
66 |
as templates. That means that a config file can also be loaded from a db
|
|
|
67 |
`$smarty->configLoad("db:my.conf")`.
|
|
|
68 |
|
|
|
69 |
See also [`{config_load}`](./language-builtin-functions/language-function-config-load.md),
|
|
|
70 |
[`$config_overwrite`](../programmers/api-variables/variable-config-overwrite.md),
|
|
|
71 |
[`$default_config_handler_func`](../programmers/api-variables/variable-default-config-handler-func.md),
|
|
|
72 |
[`getConfigVars()`](../programmers/api-functions/api-get-config-vars.md),
|
|
|
73 |
[`clearConfig()`](../programmers/api-functions/api-clear-config.md) and
|
|
|
74 |
[`configLoad()`](../programmers/api-functions/api-config-load.md)
|