How to hide certain fields to a user if they aren't referenced in a field on the node? I have a content type which has a full content and teaser display. It has a number of fields, and one of the fields on it is an Entity Reference field which references users (called field_registered_users with unlimited values allowed).

If a user views the node and they aren't referenced within the field then I want to hide certain fields on the node.

How do I do this? Should I do it in the template file or through a custom module? I also want to display a block on the page instead of the fields if this is the case.
business logic never in tpl.

You could use hook_node_view($node, $view_mode, $langcode).

In my opinion the cleanest and the most drupal way would be to create a custom formatter (mymodule_field_formatter_info) in which you should pass
the returned value (1 or 0) of your business logic to the #access property of the field

Regards.