The $iif is poor form. While I don't see a glaring problem with the syntax (i'm not looking that hard), I can tell you that you SHOULD be using a regular if-condition in this case.
if (condition) { /behavior }
not
$iif(condition,/behavior)
Perhaps if you switch to a proper if, the problem will work itself out.