In today’s quality code tip, you will learn about removing the HTML from your business logic and putting it into a view file. In programming, you want to separate out your code by its intent and purpose. Let’s discuss the what, how, and why of view files. (Side note: I’m showing you the actual code on this website which is powered by WordPress and Genesis.)
Functions and class methods are for your business logic. Their intent is to do the work such as check authorizations, interact with the database, process data and forms, assemble the components, sanitize pieces of data, and then call the view file. That is what your business logic does. It is the specifics which are unique for your project and website.
View files are responsible for presenting the content and supplying its context and meaning, i.e. the HTML. This is the code that is rendered out to the browser. The processing and work are all done before the view file is called.I'm getting the HTML out of my PHP functions & putting it into a View file #cleancode Click To Tweet
Keep your code separated by intent.
Work to organize your code by intent and purpose. Improve the quality of your craft.