This is too much logic in templates. You have data object in @ in helpers.