| 991 |
lars |
1 |
# Troubleshooting
|
| 148 |
lars |
2 |
|
| 991 |
lars |
3 |
## Smarty/PHP errors
|
| 148 |
lars |
4 |
|
|
|
5 |
Smarty can catch many errors such as missing tag attributes or malformed
|
|
|
6 |
variable names. If this happens, you will see an error similar to the
|
|
|
7 |
following:
|
|
|
8 |
|
| 991 |
lars |
9 |
```
|
|
|
10 |
Warning: Smarty: [in index.tpl line 4]: syntax error: unknown tag - '%blah'
|
|
|
11 |
in /path/to/smarty/Smarty.class.php on line 1041
|
| 148 |
lars |
12 |
|
| 991 |
lars |
13 |
Fatal error: Smarty: [in index.tpl line 28]: syntax error: missing section name
|
|
|
14 |
in /path/to/smarty/Smarty.class.php on line 1041
|
|
|
15 |
```
|
| 148 |
lars |
16 |
|
|
|
17 |
|
|
|
18 |
Smarty shows you the template name, the line number and the error. After
|
|
|
19 |
that, the error consists of the actual line number in the Smarty class
|
|
|
20 |
that the error occurred.
|
|
|
21 |
|
|
|
22 |
There are certain errors that Smarty cannot catch, such as missing close
|
|
|
23 |
tags. These types of errors usually end up in PHP compile-time parsing
|
|
|
24 |
errors.
|
|
|
25 |
|
| 991 |
lars |
26 |
`Parse error: parse error in /path/to/smarty/templates_c/index.tpl.php on line 75`
|
|
|
27 |
|
| 148 |
lars |
28 |
When you encounter a PHP parsing error, the error line number will
|
|
|
29 |
correspond to the compiled PHP script, NOT the template itself. Usually
|
|
|
30 |
you can look at the template and spot the syntax error. Here are some
|
|
|
31 |
common things to look for: missing close tags for
|
| 991 |
lars |
32 |
[`{if}{/if}`](../designers/language-builtin-functions/language-function-if.md) or
|
|
|
33 |
[`{section}{/section}`](../designers/language-builtin-functions/language-function-section.md),
|
|
|
34 |
or syntax of logic within an `{if}` tag. If you can\'t find the error, you might have to
|
| 148 |
lars |
35 |
open the compiled PHP file and go to the line number to figure out where
|
|
|
36 |
the corresponding error is in the template.
|
|
|
37 |
|
| 991 |
lars |
38 |
```
|
|
|
39 |
Warning: Smarty error: unable to read resource: "index.tpl" in...
|
|
|
40 |
```
|
|
|
41 |
or
|
|
|
42 |
```
|
|
|
43 |
Warning: Smarty error: unable to read resource: "site.conf" in...
|
|
|
44 |
```
|
| 148 |
lars |
45 |
|
| 991 |
lars |
46 |
- The [`$template_dir`](../programmers/api-variables/variable-template-dir.md) is incorrect, doesn't
|
| 148 |
lars |
47 |
exist or the file `index.tpl` is not in the `templates/` directory
|
|
|
48 |
|
| 991 |
lars |
49 |
- A [`{config_load}`](../designers/language-builtin-functions/language-function-config-load.md) function is
|
|
|
50 |
within a template (or [`configLoad()`](../programmers/api-functions/api-config-load.md) has been
|
|
|
51 |
called) and either [`$config_dir`](../programmers/api-variables/variable-config-dir.md) is
|
| 148 |
lars |
52 |
incorrect, does not exist or `site.conf` is not in the directory.
|
|
|
53 |
|
| 991 |
lars |
54 |
```
|
|
|
55 |
Fatal error: Smarty error: the $compile_dir 'templates_c' does not exist,
|
|
|
56 |
or is not a directory...
|
|
|
57 |
```
|
| 148 |
lars |
58 |
|
| 991 |
lars |
59 |
- Either the [`$compile_dir`](../programmers/api-variables/variable-compile-dir.md)is incorrectly
|
| 148 |
lars |
60 |
set, the directory does not exist, or `templates_c` is a file and
|
|
|
61 |
not a directory.
|
|
|
62 |
|
| 991 |
lars |
63 |
```
|
|
|
64 |
Fatal error: Smarty error: unable to write to $compile_dir '....
|
|
|
65 |
```
|
| 148 |
lars |
66 |
|
|
|
67 |
|
| 991 |
lars |
68 |
- The [`$compile_dir`](../programmers/api-variables/variable-compile-dir.md) is not writable by the
|
| 148 |
lars |
69 |
web server. See the bottom of the [installing
|
| 991 |
lars |
70 |
smarty](../getting-started.md#installation) page for more about permissions.
|
| 148 |
lars |
71 |
|
| 991 |
lars |
72 |
```
|
|
|
73 |
Fatal error: Smarty error: the $cache_dir 'cache' does not exist,
|
|
|
74 |
or is not a directory. in /..
|
|
|
75 |
```
|
| 148 |
lars |
76 |
|
| 991 |
lars |
77 |
- This means that [`$caching`](../programmers/api-variables/variable-caching.md) is enabled and
|
|
|
78 |
either; the [`$cache_dir`](../programmers/api-variables/variable-cache-dir.md) is incorrectly set,
|
| 148 |
lars |
79 |
the directory does not exist, or `cache/` is a file and not a
|
|
|
80 |
directory.
|
|
|
81 |
|
| 991 |
lars |
82 |
```
|
|
|
83 |
Fatal error: Smarty error: unable to write to $cache_dir '/...
|
|
|
84 |
```
|
| 148 |
lars |
85 |
|
| 991 |
lars |
86 |
- This means that [`$caching`](../programmers/api-variables/variable-caching.md) is enabled and the
|
|
|
87 |
[`$cache_dir`](../programmers/api-variables/variable-cache-dir.md) is not writable by the web
|
| 148 |
lars |
88 |
server. See the bottom of the [installing
|
| 991 |
lars |
89 |
smarty](../getting-started.md#installation) page for permissions.
|
| 148 |
lars |
90 |
|
| 991 |
lars |
91 |
```
|
|
|
92 |
Warning: filemtime(): stat failed for /path/to/smarty/cache/3ab50a623e65185c49bf17c63c90cc56070ea85c.one.tpl.php
|
|
|
93 |
in /path/to/smarty/libs/sysplugins/smarty_resource.php
|
|
|
94 |
```
|
| 148 |
lars |
95 |
|
|
|
96 |
- This means that your application registered a custom error handler
|
| 991 |
lars |
97 |
(using [set_error_handler()](https://www.php.net/set_error_handler))
|
| 148 |
lars |
98 |
which is not respecting the given `$errno` as it should. If, for
|
|
|
99 |
whatever reason, this is the desired behaviour of your custom error
|
|
|
100 |
handler, please call
|
| 991 |
lars |
101 |
[`muteExpectedErrors()`](../programmers/api-functions/api-mute-expected-errors.md) after you've
|
| 148 |
lars |
102 |
registered your custom error handler.
|
|
|
103 |
|
| 991 |
lars |
104 |
See also [debugging](../designers/chapter-debugging-console.md).
|