I want to include a php-file in my template. But sometimes the php file is not exist. I try to check it by function "file_exists", but it doesn't work.
{if file_exists("`$plugin`/button.php")}
{include_php "`$plugin`/button.php"}
{/if}
Fatal error: Uncaught --> Smarty Compiler: Syntax error in template "file:/home/user/www/site/template/template.tpl" on line 456 "{include_php "
$plugin
/button.php"}" {include_php} file '/button.php' is not readable <-- thrown in /home/user/www/site/smarty/sysplugins/smarty_internal_templatecompilerbase.php on line 456
Is there any way to check if a php file exists?
Always check your variables before trying to use them.
In this case it was the $plugin variable that is empty that makes the string concatenation fail.
If you first make sure your variables are set, then if that is true check if the file exist it should work as expected.
{if isset($plugin) && file_exists("`$plugin`/button.php")}
{include_php "$plugin/button.php"}
{/if}
In pure PHP this should work since if the isset fails it will not even try the file_exist.
Not sure about smarty though.
If it does not work this way you need to make it a separate if.