Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End MVC Re-Org – need help with templating / views Reply To: MVC Re-Org – need help with templating / views

#183432
__
Participant

It’s usually easier to write the templates if they’re in a separate file. I have three approaches:

  • separate html+php template, wrapped in an output buffer. This form is easy to write, especially since you don’t strictly need to know how it is included/parsed. I do this when clients or third parties might need to work with the template.
  • separate php template (but no output, so no output buffer needed) which returns a string when included. I like this method best (it feels very “clean” to me), but it’s more fragile in case anyone else needs to handle them, so I don’t get to use this method as often as I’d like.
  • string template written directly in the view class (or similar). I don’t really like this approach because I have to use string replacement (and/or wrap it in a function). I try not to do this except as a “fallback” template, or for really short strings.