Handle new-style memberships in templates

When an organization is related to an organization or a person related
to a person using the member property of a relationship this ensures
that relationship is displayed correctly.
Make sure that the membership is valid before rendering

This prevents 500 errors when certain pieces of information about a
membership are missing or they refer to records that no longer exist.