Smarty: E_NOTICE warnings on undefined template variables
After upgrading my PHP and Smarty installations I started getting E_NOTICE
warnings for any template variable that was not defined. There are valid reasons to have an undefined variable in your template, so I did not want to show a notice every time one is encountered. A real world example that I've encountered is:
{if $debug}
Debug: {$error_string}
{/if}
One could argue you could just test if $debug
is non-empty, but that's more typing and feels redundant. I have a lot of old templates using this sysntax and didn't want to have to update all of them. The simple solution I found in the Smarty documentation.
// Don't show missing template variables as E_NOTICE
$smarty->error_reporting = E_ALL & ~E_NOTICE;
// or
$smarty->muteUndefinedOrNullWarnings();
Note: This does not mask your normal PHP E_NOTICE
errors, just ones generated by Smarty.