Welcome Guest, Not a member yet? Register   Sign In
Better view files
#9

Honestly, the best method of getting clean view files when they contain a mix of HTML and PHP is to write clean files from the start. Further, just as with raw code, I use the indentation as a guide while I'm writing. Good auto-indent support in the editor is a start, and I find it useful to create my closing tags before filling them with content and have the editor prompt me with the closing tags so I can tell whether I forgot something. In fact, creating an outline of the view as a starting point is often very helpful in building a clean view, and, in some cases, I'll break up more complicated views into multiple files to keep it clean (for example, the content of a form might be in a separate file from the page on which the form is displayed.

In most cases, I've found tools built strictly for HTML will create more work than you would have had by just doing it by hand.

Also, as John_Betong mentioned, cleaner use of CSS and the removal of styles can help clean up the mess by just making it easier to find the individual elements. For example, you could easily add the clearfix class to the form and likely get the same result you achieved here with a clearfix div before and after your form. It should also be fairly easy to add the desired space around your form and/or panels with CSS rather than inserting an empty div with a margin-top style.

Learning to write clean HTML/CSS/JavaScript is important even if you think you're going to spend most of your professional life writing back-end code. At the very least, it helps you understand what the output should look like.

Finally, unless you have some real need for the comments in the HTML to be visible in your browser's "View Source" output, I would recommend using PHP comments, so they don't get transmitted to the client. It's a very minor thing, but the comments usually aren't aimed at the end users, but they have to put up with an extra couple of wasted bytes for something they'll never use.
Reply


Messages In This Thread
Better view files - by ignitedcms - 07-31-2015, 03:46 PM
RE: Better view files - by John_Betong - 08-01-2015, 12:20 AM
RE: Better view files - by ignitedcms - 08-02-2015, 03:28 AM
RE: Better view files - by John_Betong - 08-02-2015, 05:58 AM
RE: Better view files - by Diederik - 08-02-2015, 04:15 AM
RE: Better view files - by ignitedcms - 08-02-2015, 04:54 AM
RE: Better view files - by ignitedcms - 08-02-2015, 06:36 AM
RE: Better view files - by John_Betong - 08-02-2015, 08:18 AM
RE: Better view files - by mwhitney - 08-04-2015, 07:19 AM
RE: Better view files - by ignitedcms - 08-04-2015, 08:32 AM
RE: Better view files - by John_Betong - 08-04-2015, 09:22 AM
RE: Better view files - by ignitedcms - 08-04-2015, 10:36 AM



Theme © iAndrew 2016 - Forum software by © MyBB