I have some HTML code sections that repeat a lot through pages. I have put this HTML code inside the function so that it is easy to maintain. Although it works perfectly, I think it may not be very good practice.
function drawTable ($ item) {? & Gt; HTML code here & lt ;? I also run this problem when I want to return data using json, then the following will not work as it will be tapped: Code> $ response ['table'] = attractable ($ item); Return json_encode ($ response);
What is the correct way to handle HTML code which repeats a lot ??
Thanks
You can use ugly hered or HTML-embedded-in-php functions Instead of using the templates you want to use, which are just plain non-refundable and are not IDE-friendly.
If you have repeating sections, then load the template multiple times using the loop.
Although the templates help with drought, the primary focus is to separate the presentation from the logic. Embeding HTML in the PHP function does not do this; You do not need to avoid any quotes or break indentation / formatting to not mention it.
The syntax example when using the template:
$ data = array ('title' = & gt; 'my page', 'text' = & gt; My article '); $ Template = new template (); $ Template-> Render ('/ path / to / file.php', $ data); Your Template Page can be anything like this:
& lt; H1 & gt; & Lt ;? Php echo $ title; ? & Gt; & Lt; / H1> & Lt; P & gt; & Lt ;? Php echo $ text; ? & Gt; & Lt; / P & gt;
Comments
Post a Comment