Answer the question
In order to leave comments, you need to log in
Why do we need templating engines (pug, nunjacks, etc.) if you can type it right in php?
Let's take the following situation.
Task: make up a psd layout of 10 pages and put it on Wordpress.
I see 2 options:
1) Make up, for example, in pug. Manually transfer html to php files and replace pieces of html code with php (wp functions);
2) Try to attach some tool to pug that allows you to use php and wp functions in pug and get php files as output.
Isn't it easier then to install wp, create a starter theme and layout right away in the theme's php files?
Answer the question
In order to leave comments, you need to log in
I will probably be pecked, but, IMHO, wordpress is very far from any template engines. I don’t see any reason to use them there, since the whole engine is a solid shit code, it won’t get any better from a template engine)
In general, they are used for simplicity, security and the ability to work on templates by a person who doesn’t have a foot in php.
If you need to nagovnokodit on the knee - it's easier to use PHP.
And if you need to support the project for a long time, then a normal template engine is needed.
Security. This is automatic escaping depending on the context. Privilege escalation work: only in cases where you need to work without escaping, this is explicitly specified.
Convenient work with blocks. Template inheritance greatly simplifies working with them.
Using its simplified syntax.
You can try Laravel's Blade templating engine: this is a development of the PHP templating engine through macros, it is an intermediate option between PHP and normal templating engines.
But better use Twig if you want to be good and don't take half measures.
Template engines are a tool designed for Python/Ruby/JS. Where there is no native HTML support.
And then the reflection of the herd turns on - if the mainstream has gone for templates, then without templates you seem to be a goof.
In some places there is a reason - when you need to transfer JS & php to one template system. But this is in large projects with REST API & SPA. This rarely happens. However, these are companies with 1000-3000 programmers. It seems to them that if they have it so, then it should be so everywhere.
If the project is going to php, and there is protection from reflection, then a separate template is not needed and only complicates the system. A good reusable template system can be done in php if you have brains. Most WP sites work this way. But few people realize this. The reflection of the herd is so strong that it's easier to play along than to prove the opposite)
Still, how could there be protection against XSS attacks. But it is not exactly.
Buddy, not everyone works with Php ))
Stretching a CMS is a thankless task, you still have to change a bunch of ready-made code, even if you write without templates at all. (IMHO)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question