If you're going to use this approach, it would make sense to put this in a helper - makes the template a bit cleaner, and the method reusable.