| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | # Troubleshooting
 | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | ## Smarty/PHP errors
 | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | Smarty can catch many errors such as missing tag attributes or malformed | 
					
						
							|  |  |  | variable names. If this happens, you will see an error similar to the | 
					
						
							|  |  |  | following: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | ``` | 
					
						
							|  |  |  | Warning: Smarty: [in index.tpl line 4]: syntax error: unknown tag - '%blah' | 
					
						
							|  |  |  |        in /path/to/smarty/Smarty.class.php on line 1041 | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | Fatal error: Smarty: [in index.tpl line 28]: syntax error: missing section name | 
					
						
							|  |  |  |        in /path/to/smarty/Smarty.class.php on line 1041 | 
					
						
							|  |  |  | ``` | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  |          | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Smarty shows you the template name, the line number and the error. After | 
					
						
							|  |  |  | that, the error consists of the actual line number in the Smarty class | 
					
						
							|  |  |  | that the error occurred. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | There are certain errors that Smarty cannot catch, such as missing close | 
					
						
							|  |  |  | tags. These types of errors usually end up in PHP compile-time parsing | 
					
						
							|  |  |  | errors. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | `Parse error: parse error in /path/to/smarty/templates_c/index.tpl.php on line 75` | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  | When you encounter a PHP parsing error, the error line number will | 
					
						
							|  |  |  | correspond to the compiled PHP script, NOT the template itself. Usually | 
					
						
							|  |  |  | you can look at the template and spot the syntax error. Here are some | 
					
						
							|  |  |  | common things to look for: missing close tags for | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | [`{if}{/if}`](../designers/language-builtin-functions/language-function-if.md) or | 
					
						
							|  |  |  | [`{section}{/section}`](../designers/language-builtin-functions/language-function-section.md),  | 
					
						
							|  |  |  | or syntax of logic within an `{if}` tag. If you can\'t find the error, you might have to | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  | open the compiled PHP file and go to the line number to figure out where | 
					
						
							|  |  |  | the corresponding error is in the template. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | ``` | 
					
						
							|  |  |  | Warning: Smarty error: unable to read resource: "index.tpl" in... | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | or | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | Warning: Smarty error: unable to read resource: "site.conf" in... | 
					
						
							|  |  |  | ``` | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | -   The [`$template_dir`](../programmers/api-variables/variable-template-dir.md) is incorrect, doesn't | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  |     exist or the file `index.tpl` is not in the `templates/` directory | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | -   A [`{config_load}`](../designers/language-builtin-functions/language-function-config-load.md) function is | 
					
						
							|  |  |  |     within a template (or [`configLoad()`](../programmers/api-functions/api-config-load.md) has been | 
					
						
							|  |  |  |     called) and either [`$config_dir`](../programmers/api-variables/variable-config-dir.md) is | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  |     incorrect, does not exist or `site.conf` is not in the directory. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | ``` | 
					
						
							|  |  |  | Fatal error: Smarty error: the $compile_dir 'templates_c' does not exist, | 
					
						
							|  |  |  | or is not a directory... | 
					
						
							|  |  |  | ``` | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | -   Either the [`$compile_dir`](../programmers/api-variables/variable-compile-dir.md)is incorrectly | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  |     set, the directory does not exist, or `templates_c` is a file and | 
					
						
							|  |  |  |     not a directory. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | ``` | 
					
						
							|  |  |  | Fatal error: Smarty error: unable to write to $compile_dir '.... | 
					
						
							|  |  |  | ``` | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  |          | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | -   The [`$compile_dir`](../programmers/api-variables/variable-compile-dir.md) is not writable by the | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  |     web server. See the bottom of the [installing | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  |     smarty](../getting-started.md#installation) page for more about permissions. | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | ``` | 
					
						
							|  |  |  | Fatal error: Smarty error: the $cache_dir 'cache' does not exist, | 
					
						
							|  |  |  | or is not a directory. in /.. | 
					
						
							|  |  |  | ``` | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  |          | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | -   This means that [`$caching`](../programmers/api-variables/variable-caching.md) is enabled and | 
					
						
							|  |  |  |     either; the [`$cache_dir`](../programmers/api-variables/variable-cache-dir.md) is incorrectly set, | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  |     the directory does not exist, or `cache/` is a file and not a | 
					
						
							|  |  |  |     directory. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | ``` | 
					
						
							|  |  |  | Fatal error: Smarty error: unable to write to $cache_dir '/... | 
					
						
							|  |  |  | ``` | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | -   This means that [`$caching`](../programmers/api-variables/variable-caching.md) is enabled and the | 
					
						
							|  |  |  |     [`$cache_dir`](../programmers/api-variables/variable-cache-dir.md) is not writable by the web | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  |     server. See the bottom of the [installing | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  |     smarty](../getting-started.md#installation) page for permissions. | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | ``` | 
					
						
							|  |  |  | Warning: filemtime(): stat failed for /path/to/smarty/cache/3ab50a623e65185c49bf17c63c90cc56070ea85c.one.tpl.php  | 
					
						
							|  |  |  | in /path/to/smarty/libs/sysplugins/smarty_resource.php | 
					
						
							|  |  |  | ``` | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-22 22:08:38 +02:00
										 |  |  | -   This means that your application registered a custom error handler | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  |     (using [set_error_handler()](https://www.php.net/set_error_handler)) | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  |     which is not respecting the given `$errno` as it should. If, for | 
					
						
							|  |  |  |     whatever reason, this is the desired behaviour of your custom error | 
					
						
							|  |  |  |     handler, please call | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  |     [`muteExpectedErrors()`](../programmers/api-functions/api-mute-expected-errors.md) after you've | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  |     registered your custom error handler. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-05 23:14:10 +01:00
										 |  |  | See also [debugging](../designers/chapter-debugging-console.md). |