Why don't you use templates? Mixing code and view is bad.

Please see my answer here and here.