Is putting PHP right inside of HTML like that best practice? Seems a bit sloppy. No?
Yes and no. In this case, it is wholly templating-related, and that’s fine. It’s what PHP is for. It’s the business logic of your application that shouldn’t be mixed in with HTML.
The fact that you’re worried about this sort of thing is a good sign, though.