Is the following acceptable, even if $my_flag
may not be set?
{if ( $my_flag )}
// Vrooom
{/if}
Do I always need isset
to ensure notices aren't thrown, or does Smarty3 take care of things?
Is the following acceptable, even if $my_flag
may not be set?
{if ( $my_flag )}
// Vrooom
{/if}
Do I always need isset
to ensure notices aren't thrown, or does Smarty3 take care of things?
It is acceptable, but PHP will warn you that $my_flag
is undefined.
I would do something like that:
{if isset($my_flag)}
{if $my_flag == 123}
<p>print something</p>
{/if}
{/if}
If you will try your current script everything will work, but it will log a notice. The above script makes sure the only if the variable is set then do something.
However, since Smarty is cached you may have to reload the page a few times to see the changes (unless you specify $smarty_obj->force_compile = true;
).