Should I learn Smarty for PHP templates?

I am building a simple 10-page site using an MVC-like architecture. Is it worth exploring the mechanism of Smarty templates?

+6
source share
8 answers

Template engines add overhead.

You should only use the template engine if you need others to create / edit templates and you do not want them to be able to use PHP.

If you're the only companion, defiantly go with simple PHP. If your team can be trusted (they are all developers), stick with simple PHP. If you have designers who don’t know PHP or, more importantly, letting them use PHP is dangerous, then use Smarty or another template engine.

That being said, you are wondering if you should study Smarty. You will need to learn Smarty by creating templates with Smarty. You do not need to learn Smarty if you just implement the Smarty template engine.

+5
source

Smarty is a template engine that is easy to learn and use, but I highly recommend learning and using Twig instead.

+3
source

not necessary.

A 10-page site is easy to build. if you want to use Smarty, you will have to spend a little more time to learn it at the beginning ~

+2
source

Template language is a good choice when you dynamically generate HTML. Be it Smarty or something else (for PHP), Razor or Forms (for ASP.NET) or something completely different (John Resig client micro-templating , maybe).

+2
source

PHP is a decent template language. If there is no need for advanced features, custom solutions will only complicate what seems like a fairly simple setup.

+2
source

I never looked back, looking smart. Others scared me, saying it was very difficult. I use Twig for almost everything that I do now, even for trifles. Even if it’s not worth it for a small site, I think it’s worth studying for a long time - getting good grounding in inheritance and template blocks is absolutely justified.

Check this:

<?php echo htmlspecialchars(\$var, ENT_QUOTES, 'UTF-8') ?> 

against.

 {{ var|escape }} 

yummy:

 {% for i in 0..10 %} * {{ i }} {% endfor %} 
+2
source

I used Smarty a long time ago, I would recommend that you do not need to use the Template Engine. Smarty slows down the whole system, because its main source code is very complex and somehow unnecessary. If I had a recommendation on the Engine pattern, I would say:

1) Use a basic and lightweight template engine, such as XTemplate . I'm not sure if it is still developing, but it is really useful, all in one class file, ready to use. The syntax is also clear and sweet.

2) Write your own template engine so that you can configure it yourself that best suits your current system.

But, however, for a tiny and small project (less than 5-7 pages), in which you can control everything, then using the Engine template is probably not necessary.

+2
source

I agree with what has been said above. For a simple site with 10 pages, use PHP on the MVC model or use the easy and fast template engine like RainTPL or Savant .

This test may be biased because it was published by RainTPL. But in any case, I compared several templates with the Apache ab utility and I can confirm these results. RainTPL is fast.

+1
source

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


All Articles