Need help with a not working code

You got examples for a working $IF syntax in one of your earlier posts from 2017, e.g.
/t/18676/1

why didn't you use that template?