I don't think logic like this should be hardcoded in a template - to me it is a hack.