Technology

Results of Using a Lesser-Known Template Engine

Exploring the switch from Smarty to Raintpl for better PHP performance, detailing the advantages and disadvantages encountered.

Sangrak
Results of Using a Lesser-Known Template Engine

A while back, I switched from using Smarty, a well-known template engine in PHP, to Raintpl mainly because of performance issues.

After converting dozens of HTML pages to Raintpl, I did see some improvement in performance, but it wasn't as significant as I had hoped, considering the amount of work it took. Still, it was a worthwhile effort.

However, as I continued working with Raintpl, I began to notice its pros and cons more clearly, and eventually, the cons outweighed the pros. I started thinking it might have been better to switch to another well-known engine with better performance. Here are the pros and cons I found:

Pros:

  • If there's a bug, you can fix it yourself.
  • Since it's a buggy open source, there's a lot to fix and commit, which can be fun as you contribute.
  • The parsing engine isn't very robust, which means it doesn't have complex logic and performs well.
  • It's easy to tune for performance enhancements on your own.

Cons:

  • The lack of auto-completion support for the language in IDEs makes writing HTML difficult, especially with syntax reformatting.
  • The parsing engine's weaknesses can lead to unexpected issues if you try to add new syntax (like not being able to use a certain syntax more than once per line).
  • It's so easy to customize that you might forget the purpose of a template engine and overload it with excessive functionality.

I used to code easily and quickly with just simple syntax highlighting editors, but in recent years, I've become so accustomed to smart IDEs that it's become uncomfortable to use anything that's not properly supported by the IDE. This has made using Raintpl particularly inconvenient.

Next time I need a template engine in PHP, I plan to use Twig. I've tried it a few times, and it seems pretty good, plus it's supported by PHPStorm, which I use. I won't be going back to Smarty; it's just too old and slow now.

More on this topic