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