30

what is the code for smarty for if (!isset($var)){ ?

if using {if $x eq '5'} when $x is not defined in smarty , it gives an error function call 'get_template_vars' is unknown or deprecated. . this is what i believe so far as i lost hope in trying to know where did this error come from !

Thanky you .

Rami Dabain
  • 4,709
  • 12
  • 62
  • 106

3 Answers3

40
{if ! isset($var)}
body must be at least 30 characters. :)
{/if}
Timofey Stolbov
  • 4,501
  • 3
  • 40
  • 45
7

Try this.

{if $missing_var|default:FALSE}
NOT MISSING
{else}
MISSING
{/if}
Vladimir Djuricic
  • 4,323
  • 1
  • 21
  • 22
1

Try This

{if $var}
   Active
{else}
   Inactive
{/if}
Gunaseelan
  • 2,494
  • 5
  • 36
  • 43
Anil R
  • 289
  • 1
  • 6
  • 4
    what if the $var was SET and containing value of FALSE ? – Rami Dabain Jul 20 '16 at 20:44
  • if $var is not set, this will throw undefined notices in smart3. – seven Sep 16 '20 at 10:49
  • @RamiDabain Avoid using boolean in if statements, try to use a string like $var = 'hasValue' instead if you need to do a conditional anyway. This can be a returning issue in any language you use, javascript as well. – Dgloria Oct 25 '21 at 09:32
  • When you have E_NOTICE activated, this solution doesn't work. – Meloman Aug 18 '22 at 05:15