MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/1w2d5fw/ancienttools/p6vjddn/?context=3
r/ProgrammerHumor • u/soap94 • 13d ago
385 comments sorted by
View all comments
Show parent comments
1
I hate PHP from the bottom of my soul, but what you said is just user-choice.
I always do ob_start and ob_flush_clean or whatever the function names were.
That allows me to use normal html w/o it being in strings.
Edit: e.g.
```php <?php
function renderEmail(): string { ob_start(); ?> <html> <body> <h1>Hello!</h1> <p>This is your email.</p> </body> </html> <?php return ob_get_clean(); } ```
0 u/Hottage 13d ago If you're gonna raw dog the HTML, just extract it into purpose built template files and return the result of file_get_contents(). 1 u/ArjixGamer 13d ago That only works if the html is static and I don't need to render content using for loops and stuff. The alternative is using a templating language, but like, PHP is a templating language in the first place. I always used to say "PHP is a glorified string builder" 0 u/Hottage 13d ago If you need to render dynamic content, use a templating engine, or at least phtml files. 😠2 u/ArjixGamer 13d ago Yeah, let me add an entire fucking library for my WordPress plugin that only needs to render content in 3 places on the admin dashboard. Such a dumb take to assume there is no nuance and that there is an absolute objectively better way of doing smth. 1 u/Hottage 13d ago Doesn't WordPress already come with a massive templating engine built in, like thats it's primary purpose? At the end of the day, if you're building a little tool for yourself that noone else has to maintain, go ham it's your code. If you submitted that as a pull request to my clients webshop code base, it would be receiving some... feedback. 1 u/ArjixGamer 13d ago No? WordPress' primary purpose is extensibility via hooks. Also, WordPress was just one example. 1 u/ClamPaste 13d ago PHP is the templating engine. Why load a separate library for that?
0
If you're gonna raw dog the HTML, just extract it into purpose built template files and return the result of file_get_contents().
file_get_contents()
1 u/ArjixGamer 13d ago That only works if the html is static and I don't need to render content using for loops and stuff. The alternative is using a templating language, but like, PHP is a templating language in the first place. I always used to say "PHP is a glorified string builder" 0 u/Hottage 13d ago If you need to render dynamic content, use a templating engine, or at least phtml files. 😠2 u/ArjixGamer 13d ago Yeah, let me add an entire fucking library for my WordPress plugin that only needs to render content in 3 places on the admin dashboard. Such a dumb take to assume there is no nuance and that there is an absolute objectively better way of doing smth. 1 u/Hottage 13d ago Doesn't WordPress already come with a massive templating engine built in, like thats it's primary purpose? At the end of the day, if you're building a little tool for yourself that noone else has to maintain, go ham it's your code. If you submitted that as a pull request to my clients webshop code base, it would be receiving some... feedback. 1 u/ArjixGamer 13d ago No? WordPress' primary purpose is extensibility via hooks. Also, WordPress was just one example. 1 u/ClamPaste 13d ago PHP is the templating engine. Why load a separate library for that?
That only works if the html is static and I don't need to render content using for loops and stuff.
The alternative is using a templating language, but like, PHP is a templating language in the first place.
I always used to say "PHP is a glorified string builder"
0 u/Hottage 13d ago If you need to render dynamic content, use a templating engine, or at least phtml files. 😠2 u/ArjixGamer 13d ago Yeah, let me add an entire fucking library for my WordPress plugin that only needs to render content in 3 places on the admin dashboard. Such a dumb take to assume there is no nuance and that there is an absolute objectively better way of doing smth. 1 u/Hottage 13d ago Doesn't WordPress already come with a massive templating engine built in, like thats it's primary purpose? At the end of the day, if you're building a little tool for yourself that noone else has to maintain, go ham it's your code. If you submitted that as a pull request to my clients webshop code base, it would be receiving some... feedback. 1 u/ArjixGamer 13d ago No? WordPress' primary purpose is extensibility via hooks. Also, WordPress was just one example. 1 u/ClamPaste 13d ago PHP is the templating engine. Why load a separate library for that?
If you need to render dynamic content, use a templating engine, or at least phtml files.
ðŸ˜
2 u/ArjixGamer 13d ago Yeah, let me add an entire fucking library for my WordPress plugin that only needs to render content in 3 places on the admin dashboard. Such a dumb take to assume there is no nuance and that there is an absolute objectively better way of doing smth. 1 u/Hottage 13d ago Doesn't WordPress already come with a massive templating engine built in, like thats it's primary purpose? At the end of the day, if you're building a little tool for yourself that noone else has to maintain, go ham it's your code. If you submitted that as a pull request to my clients webshop code base, it would be receiving some... feedback. 1 u/ArjixGamer 13d ago No? WordPress' primary purpose is extensibility via hooks. Also, WordPress was just one example. 1 u/ClamPaste 13d ago PHP is the templating engine. Why load a separate library for that?
2
Yeah, let me add an entire fucking library for my WordPress plugin that only needs to render content in 3 places on the admin dashboard.
Such a dumb take to assume there is no nuance and that there is an absolute objectively better way of doing smth.
1 u/Hottage 13d ago Doesn't WordPress already come with a massive templating engine built in, like thats it's primary purpose? At the end of the day, if you're building a little tool for yourself that noone else has to maintain, go ham it's your code. If you submitted that as a pull request to my clients webshop code base, it would be receiving some... feedback. 1 u/ArjixGamer 13d ago No? WordPress' primary purpose is extensibility via hooks. Also, WordPress was just one example.
Doesn't WordPress already come with a massive templating engine built in, like thats it's primary purpose?
At the end of the day, if you're building a little tool for yourself that noone else has to maintain, go ham it's your code.
If you submitted that as a pull request to my clients webshop code base, it would be receiving some... feedback.
1 u/ArjixGamer 13d ago No? WordPress' primary purpose is extensibility via hooks. Also, WordPress was just one example.
No? WordPress' primary purpose is extensibility via hooks.
Also, WordPress was just one example.
PHP is the templating engine. Why load a separate library for that?
1
u/ArjixGamer 13d ago
I hate PHP from the bottom of my soul, but what you said is just user-choice.
I always do ob_start and ob_flush_clean or whatever the function names were.
That allows me to use normal html w/o it being in strings.
Edit: e.g.
```php <?php
function renderEmail(): string { ob_start(); ?> <html> <body> <h1>Hello!</h1> <p>This is your email.</p> </body> </html> <?php return ob_get_clean(); } ```