Is it bad practice to write HTML markup using only PHP echo expressions?

There is a guy at work who pretty much writes all his html markup using echo statements. It looks very clean, and I like it a lot, but I remember that this is bad practice because it gets a little when you have to write large amounts of markup. What is the best practice?

+3
source share
7 answers

Well, given the answers, I felt I should put my 2 cents.

First of all, it depends on the project. I personally use PHP as a template engine, not a third-party one. This way, I keep my presentation logic in a β€œtemplate”, which is just php markup that uses multiple echoes, but the echo operators simply reflect the relevant data, not the html code. Breaking in and out of PHP is not a bad practice if everything is done correctly.

, HTML "", HTML , ( , heredoc , foreach loop heredoc ). - / , / , <?php echo $data; ?>, , .

, . , 10 -, 100 -, html, , , , /.

+7

, , -. , HEREDOC, echo, print PHP .

, , .

+4

. , .

, ( smarty.net).

+3

/, PHP, .

, HEREDOC. TON , , , .

+2

, . Echo, , PHP php require, , , , . , , . , .

+1

html , .

0

Sounds good, considering that someday you will want to change technologies (for example, from php to asp.net or ruby ​​on rails). Seems like "Separation of problems"> is thrown out of the window.

0
source

Source: https://habr.com/ru/post/1756221/


All Articles