0

I have a smarty project. in the php file I will assign the variable bar dynamically.

in the php file's corresponding template:

{if $bar}{$bar}{/if}

but I will get bellow error:

Notice: Undefined index: bar in /Users/sof/Desktop/TestIOS/smarty-test02/templates_c/6f98597c1882f0124e0891c8343f1404eff83e24_0.file.test.tpl.cache.php on line 63

Notice: Trying to get property of non-object in /Users/sof/Desktop/TestIOS/smarty-test02/templates_c/6f98597c1882f0124e0891c8343f1404eff83e24_0.file.test.tpl.cache.php on line 63

How can I judge a variable whether is assign?

sof-03
  • 2,255
  • 4
  • 15
  • 33
  • Possible duplicate of [How to verify if $\_GET exists?](https://stackoverflow.com/questions/12019684/how-to-verify-if-get-exists) – Alex Jul 20 '18 at 06:48

1 Answers1

1

You can use PHP's isset function.

{if isset($bar)}{$bar}{/if}
wobsoriano
  • 12,348
  • 24
  • 92
  • 162