Here is the question that has been listening to me for a while, it is currently considered good practice to indent HTML code, but I have indentation code for reservation in the MVC template, here is an example (silly):
HTML code:
<!DOCTYPE html> <html> <head> <title>Testing MVC Indentation</title> </head> <body> <?php View('h1', 'I am a Level 1 Header'); ?> <table> <tr> <td> <?php View('h1', 'I am a Level 1 Header Inside a Table'); ?> </td> </tr> </table> </body> </html>
To backtrack correctly, the first call to the h1 (or partial) view should return:
\t<h1>I am a Level 1 Header</h1>
While the second view call to h1 should return:
\t\t\t\t<h1>I am a Level 1 Header Inside a Table</h1>
However, the representation of h1 has no idea about the indentation area, since in hell can it return the data properly indented? In addition, ignoring indentation in views can reveal part of the application logic (check the HTML source code of this page after <div id="content"> for an example in the real world):
<body> <h1>I am a Level 1 Header</h1> <table> <tr> <td> <h1>I am a Level 1 Header Inside a Table</h1> </td> </tr> </table> </body>
Indentation does not solve all problems at all, but it also makes reading and maintenance difficult:
<body> <h1>I am a Level 1 Header</h1> <table> <tr> <td> <h1>I am a Level 1 Header Inside a Table</h1> </td> </tr> </table> </body>
The only possible solution that I see in this problem is to use Tidy and output buffering , but I wonder if it's worth it, as this will make processing and loading unnecessarily (?) Slow. In addition, this will not simplify the maintenance of HTML code, since it only gives indentation, not the source.
I apologize for the "basic" question, but in recent years I have been focusing on business logic, and I was not connected with the world of presentations - in the good old days, my HTML code was completely biased, but again I also used spreadsheets to design the layout - just trying to catch up now.
Any solutions / ideas on this?
Matters Related:
- Are you backing away from your HTML?
- Are you creating beautifully formatted HTML?
- How to indent PHP / HTML mixed code?