Based on the comments:
generic template works, but custom does not
custom template overrides visibility rules
I would surmise that the problem is with the visibility, since the conditional field is likely only hidden, and not actually being removed - this would cause the code to execute every time, while in a standard render() it would remain hidden
Using [Devel][1]Devel and specifically the dpm() function, I would find the element in the field array that manages the visibility of the field and use that as the basis for the if statement.
A suite of modules containing fun for module developers and themers [1]: https://www.drupal.org/project/devel