It would be good to put this logic in the view instead of the template